Compare commits

...

2 commits

Author SHA1 Message Date
4d67a5480f Add verzweigungsvectoren 2024-11-14 21:52:57 +01:00
53f8c2034c Fix bug and add reverse search for minimum 2024-11-14 21:52:45 +01:00
3 changed files with 55 additions and 1 deletions

View file

@ -155,8 +155,11 @@ enum Method {
#[derive(Debug, Parser)]
struct Args {
filename: PathBuf,
#[clap(default_value = "reduction2")]
method: Method,
k: Option<u16>,
#[clap(short, long)]
reverse: bool,
}
fn main() {
@ -169,6 +172,20 @@ fn main() {
let r = vertex_cover(&graph, k, args.method);
eprintln!("{}: {:?}", k, start.elapsed());
r
} else if args.reverse {
let mut k = graph.num_vertices();
let mut last_solution = None;
loop {
let start = std::time::Instant::now();
let r = vertex_cover(&graph, k, args.method);
eprintln!("{}: {:?}", k, start.elapsed());
if let Some(r) = r {
k = r.len() as u16 - 1;
last_solution = Some(r);
} else {
break last_solution;
};
}
} else {
let mut k = 0;
loop {

View file

@ -237,6 +237,8 @@ pub fn reduction2(graph: &mut Graph, k: u16) -> Option<Vec<u16>> {
let _ = graph.reinsert_vertices(1);
r
} else if graph.is_empty() {
Some(Vec::new())
} else if k == 0 {
if graph.is_empty() {
Some(Vec::new())
@ -343,6 +345,10 @@ pub fn reduction2(graph: &mut Graph, k: u16) -> Option<Vec<u16>> {
}
}
} else if let Some(vertex) = graph.get_vertex_with_degree_greater(3) {
if k < 1 {
return None;
}
graph.remove_vertex(vertex);
match reduction2(graph, k - 1) {
@ -374,6 +380,6 @@ pub fn reduction2(graph: &mut Graph, k: u16) -> Option<Vec<u16>> {
}
}
} else {
unreachable!()
unreachable!("{k}")
}
}

31
verzweigungsvectoren/main.py Executable file
View file

@ -0,0 +1,31 @@
#!/usr/bin/env python
from numpy import roots,isreal
from itertools import combinations_with_replacement
solutions = []
s = [1, 2, 3, 4, 5, 6, 7, 8, 9]
for i in range(2, 7):
for j in combinations_with_replacement(s, i):
p = [-j.count(k) for k in range(max(j) + 1)]
p[0] = 1
r = [float(k) for k in roots(p) if isreal(k) and k > 0.0]
# print(j, max(j), p, r)
solutions.append((j, r[0]))
solutions.sort(key=lambda e: e[1])
for s in solutions:
print(f"{s[1]}\t{s[0]}")