Skip to content
Snippets Groups Projects
Commit 93a36dce authored by Valerian Wintner's avatar Valerian Wintner
Browse files

Fix: Counter not shared.

parent d86380cd
No related branches found
No related tags found
No related merge requests found
......@@ -22,7 +22,7 @@
<text text-anchor="middle" x="106.21" y="-96.11" font-family="Times,serif" font-size="14.00">2</text>
</g>
<!-- 1&#45;&gt;2 -->
<g id="edge6" class="edge">
<g id="edge8" class="edge">
<title>1&#45;&gt;2</title>
<path fill="none" stroke="black" d="M36.03,-94.3C47.73,-93.02 63.52,-92.73 77.06,-93.43"/>
<polygon fill="black" stroke="black" points="77.09,-96.94 87.32,-94.21 77.62,-89.96 77.09,-96.94"/>
......@@ -35,13 +35,13 @@
<text text-anchor="middle" x="106.21" y="-19.11" font-family="Times,serif" font-size="14.00">6</text>
</g>
<!-- 1&#45;&gt;6 -->
<g id="edge7" class="edge">
<g id="edge9" class="edge">
<title>1&#45;&gt;6</title>
<path fill="none" stroke="black" d="M36.03,-84.59C49.53,-72.54 68.49,-55.6 83.15,-42.51"/>
<polygon fill="black" stroke="black" points="85.66,-44.96 90.79,-35.69 81,-39.74 85.66,-44.96"/>
</g>
<!-- 2&#45;&gt;1 -->
<g id="edge8" class="edge">
<g id="edge7" class="edge">
<title>2&#45;&gt;1</title>
<path fill="none" stroke="black" d="M87.32,-105.4C75.44,-106.64 59.6,-106.88 46.17,-106.13"/>
<polygon fill="black" stroke="black" points="46.28,-102.63 36.03,-105.31 45.72,-109.6 46.28,-102.63"/>
......@@ -53,7 +53,7 @@
<text text-anchor="middle" x="194.42" y="-96.11" font-family="Times,serif" font-size="14.00">3</text>
</g>
<!-- 2&#45;&gt;3 -->
<g id="edge9" class="edge">
<g id="edge6" class="edge">
<title>2&#45;&gt;3</title>
<path fill="none" stroke="black" d="M133.55,-99.81C143.84,-99.81 155.64,-99.81 166.03,-99.81"/>
<polygon fill="black" stroke="black" points="166.22,-103.31 176.22,-99.81 166.22,-96.31 166.22,-103.31"/>
......
......@@ -22,7 +22,7 @@
<text text-anchor="middle" x="106.21" y="-96.11" font-family="Times,serif" font-size="14.00">2</text>
</g>
<!-- 1&#45;&gt;2 -->
<g id="edge6" class="edge">
<g id="edge8" class="edge">
<title>1&#45;&gt;2</title>
<path fill="none" stroke="black" d="M36.03,-94.3C47.73,-93.02 63.52,-92.73 77.06,-93.43"/>
<polygon fill="black" stroke="black" points="77.09,-96.94 87.32,-94.21 77.62,-89.96 77.09,-96.94"/>
......@@ -35,13 +35,13 @@
<text text-anchor="middle" x="106.21" y="-19.11" font-family="Times,serif" font-size="14.00">6</text>
</g>
<!-- 1&#45;&gt;6 -->
<g id="edge7" class="edge">
<g id="edge9" class="edge">
<title>1&#45;&gt;6</title>
<path fill="none" stroke="black" d="M36.03,-84.59C49.53,-72.54 68.49,-55.6 83.15,-42.51"/>
<polygon fill="black" stroke="black" points="85.66,-44.96 90.79,-35.69 81,-39.74 85.66,-44.96"/>
</g>
<!-- 2&#45;&gt;1 -->
<g id="edge8" class="edge">
<g id="edge7" class="edge">
<title>2&#45;&gt;1</title>
<path fill="none" stroke="black" d="M87.32,-105.4C75.44,-106.64 59.6,-106.88 46.17,-106.13"/>
<polygon fill="black" stroke="black" points="46.28,-102.63 36.03,-105.31 45.72,-109.6 46.28,-102.63"/>
......@@ -53,7 +53,7 @@
<text text-anchor="middle" x="194.42" y="-96.11" font-family="Times,serif" font-size="14.00">3</text>
</g>
<!-- 2&#45;&gt;3 -->
<g id="edge9" class="edge">
<g id="edge6" class="edge">
<title>2&#45;&gt;3</title>
<path fill="none" stroke="black" d="M133.55,-99.81C143.84,-99.81 155.64,-99.81 166.03,-99.81"/>
<polygon fill="black" stroke="black" points="166.22,-103.31 176.22,-99.81 166.22,-96.31 166.22,-103.31"/>
......
......@@ -2,14 +2,17 @@
* A simple graph structure, using
*/
use std::borrow::BorrowMut;
use std::cell::RefCell;
use std::collections::{HashMap, HashSet};
use std::hash::Hash;
use tracing::{debug, info, trace};
use std::rc::Rc;
use tracing::debug;
#[derive(PartialOrd, Ord, Clone, Debug)]
pub struct RedNode {
pub id: String,
pub counter: u32,
pub counter: Rc<RefCell<u32>>,
}
impl PartialEq for RedNode {
......@@ -45,16 +48,13 @@ fn insert_node(node: String, additional_winning: &mut AdditionalWinning, pred: &
let predecessors = pred.entry(node);
predecessors.and_modify(|predecessors| {
let mut changed_predecessors = HashSet::new();
for predecessor in predecessors.iter() {
let RedNode { id, counter } = predecessor;
let counter = counter - 1;
for mut predecessor in predecessors.iter() {
let counter = predecessor.counter.take() - 1;
predecessor.counter.replace(counter);
if counter == 0 {
to_insert.push(id.clone());
to_insert.push(predecessor.id.clone());
} else {
changed_predecessors.insert(RedNode {
id: id.clone(),
counter,
});
changed_predecessors.insert(predecessor.clone());
}
}
*predecessors = changed_predecessors
......
mod arena;
use std::cell::RefCell;
use std::collections::{HashMap, HashSet};
use std::fs::{self, File};
use std::io::Write;
use std::rc::Rc;
use clap::Parser;
......@@ -13,6 +15,7 @@ use graphviz_rust::cmd::{CommandArg, Format};
use graphviz_rust::printer::{DotPrinter, PrinterContext};
use graphviz_rust::*;
use graphviz_rust::{exec, parse};
use tracing::{debug, info};
use tracing_subscriber::fmt;
use tracing_subscriber::prelude::__tracing_subscriber_SubscriberExt;
use tracing_subscriber::util::SubscriberInitExt;
......@@ -54,13 +57,20 @@ fn main() {
.init();
}
info!("Reading graph from in-file..");
let input = fs::read_to_string(args.in_file).expect("Could not read infile!");
let g = parse(&input).unwrap();
let (greens, reds, final_positions, succ, pred) = build_inputs(&g);
debug!("Green nodes: {:?}", greens);
debug!("Red nodes: {:?}", reds);
debug!("Final positions: {:?}", final_positions);
debug!("Edges: {:#?}", succ);
debug!("Predecessors (only with red): {:#?}", pred);
// dbg!(greens, reds, final_positions, succ, pred);
info!("Computing winning positions..");
let winners = arena::winning_positions(&greens, &final_positions, &succ, pred);
if let Some(path) = args.out {
......@@ -141,17 +151,20 @@ fn build_inputs(g: &Graph) -> (Nodes, Nodes, WinningPositions, Successors, Prede
}
}
}
// Finally, add the predecessors. Here, the count is needed, initialized with the #outgoing_edges for red nodes.
for (predecessor, successors) in &succ {
if reds.contains(predecessor) {
let pre_node = RedNode {
id: predecessor.clone(),
counter: successors.len() as u32,
};
for successor in successors {
let predecessors = pred.entry(successor.clone()).or_default();
predecessors.insert(pre_node.clone());
}
}
// Finally, add the predecessors. Here, the count is needed, initialized with the #outgoing_edges for red nodes.
for red in reds.iter() {
debug!("Red: {}", red);
if let Some(successors) = &succ.get(red) {
let pre_node = RedNode {
id: red.clone(),
counter: Rc::new(RefCell::new(successors.len() as u32)),
};
for successor in successors.iter() {
let predecessors = pred.entry(successor.clone()).or_default();
predecessors.insert(pre_node.clone());
}
}
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment