Skip to content

Commit

Permalink
rewind clingo and clingo-derive and minor tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
sthiele committed Oct 23, 2019
1 parent 66c6f1b commit 1066ffa
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 73 deletions.
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ publish = false
edition = "2018"

[dependencies]
clingo = { path ="../clingo-rs" , version="0.5.0" }
clingo-derive = { path ="../clingo_derive" , version="*" }
clingo = "0.4.3"
clingo-derive = "*"
termion = "1"
structopt = "0.2"
failure = "0.1"
Expand Down
98 changes: 36 additions & 62 deletions src/bin/opt_graph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ fn main() {
let (scenfit, repair_score) =
get_opt_add_remove_edges(&graph, &profiles, &new_inputs, &setting).unwrap();
println!("done.");
print!(
println!(
"\nThe network and data can reach a scenfit of {} with repairs of score {}",
scenfit, repair_score
);
Expand All @@ -176,7 +176,7 @@ fn main() {
let (scenfit, repair_score) =
get_opt_remove_edges(&graph, &profiles, &new_inputs, &setting).unwrap();
println!("done.");
print!(
println!(
"\nThe network and data can reach a scenfit of {} with {} removed edges.",
scenfit, repair_score
);
Expand All @@ -185,11 +185,11 @@ fn main() {
};

// compute optimal repairs
if let Some(max_repairs) = opt.max_repairs {
let repairs = match opt.repair_mode {
Some(RepairMode::OptGraph) => {
if setting.ep {
if repair_score > 0 {
if repair_score > 0 {
if let Some(max_repairs) = opt.max_repairs {
let repairs = match opt.repair_mode {
Some(RepairMode::OptGraph) => {
if setting.ep {
let mut repairs = vec![];
for new_edges in redges {
//TODO return only max_repairs solutions
Expand All @@ -210,18 +210,6 @@ fn main() {
}
repairs
} else {
let mut repairs = vec![];
for new_edges in redges {
let mut repair = vec![];
for e in new_edges.iter() {
repair.push(*e);
}
repairs.push(repair);
}
repairs
}
} else {
if repair_score > 0 {
get_opt_repairs_add_remove_edges(
&graph,
&profiles,
Expand All @@ -232,52 +220,38 @@ fn main() {
&setting,
)
.unwrap()
} else {
vec![]
}
}
}
Some(RepairMode::Flip) => {
if repair_score > 0 {
get_opt_repairs_flip_edges(
&graph,
&profiles,
&new_inputs,
scenfit,
repair_score,
max_repairs,
&setting,
)
.unwrap()
} else {
vec![]
}
}
_ => {
if repair_score > 0 {
get_opt_repairs_remove_edges(
&graph,
&profiles,
&new_inputs,
scenfit,
repair_score,
max_repairs,
&setting,
)
.unwrap()
} else {
vec![]
}
}
};
Some(RepairMode::Flip) => get_opt_repairs_flip_edges(
&graph,
&profiles,
&new_inputs,
scenfit,
repair_score,
max_repairs,
&setting,
)
.unwrap(),
_ => get_opt_repairs_remove_edges(
&graph,
&profiles,
&new_inputs,
scenfit,
repair_score,
max_repairs,
&setting,
)
.unwrap(),
};

let mut count = 0;
for r in repairs {
count += 1;
println!("\nRepair {}: ", count);
for e in r {
let repair_op = into_repair(&e).unwrap();
println!(" {}", repair_op);
let mut count = 0;
for r in repairs {
count += 1;
println!("\nRepair {}: ", count);
for e in r {
let repair_op = into_repair(&e).unwrap();
println!(" {}", repair_op);
}
}
}
}
Expand Down
14 changes: 5 additions & 9 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -265,12 +265,10 @@ fn member(elem: Symbol, list: Symbol) -> Result<Symbol, Error> {
} else {
member(elem, arguments[0])
}
} else if elem == list {
Symbol::create_id("true", true)
} else {
if elem == list {
Symbol::create_id("true", true)
} else {
Symbol::create_id("false", true)
}
Symbol::create_id("false", true)
}
}
Ok(_) => {
Expand Down Expand Up @@ -1010,10 +1008,8 @@ pub fn get_opt_add_remove_edges_greedy(
bscenfit = n2scenfit; // update bscenfit
brepscore = n2repscore;
}
if n2scenfit == bscenfit {
if n2repscore < brepscore {
brepscore = n2repscore
}
if n2scenfit == bscenfit && n2repscore < brepscore {
brepscore = n2repscore;
}

let nedges = extract_addedges(&symbols2).unwrap();
Expand Down

0 comments on commit 1066ffa

Please sign in to comment.