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

only red nodes in predecessor

parent 52202216
No related branches found
No related tags found
No related merge requests found
- extract nodes and edges from original graph
- extract nodes and edges from original graph -- done
- add custom attribute for:
- color
- starting position
- goal position
- run algorithm on custom data structure (map of sets?)
- goal position -- done
- run algorithm on custom data structure (map of sets?) -- done
- cli
- different executable for displaying the graph, and for running the strategy-check
- validity-check of input.
\ No newline at end of file
......@@ -6,52 +6,30 @@ use std::collections::{HashMap, HashSet};
use std::hash::Hash;
#[derive(PartialOrd, Ord, Clone, Debug)]
pub enum PlayingNode {
Red { id: String, counter: u32 },
Green { id: String },
pub struct RedNode {
pub id: String,
pub counter: u32,
}
impl PlayingNode {
pub fn id(&self) -> &String {
match self {
PlayingNode::Red { id, .. } => id,
PlayingNode::Green { id } => id,
}
}
}
impl PartialEq for PlayingNode {
impl PartialEq for RedNode {
fn eq(&self, other: &Self) -> bool {
match (self, other) {
(
Self::Red {
id: l_id,
counter: l_counter,
},
Self::Red {
id: r_id,
counter: r_counter,
},
) => l_id == r_id && l_counter == r_counter,
(Self::Green { id: l_id }, Self::Green { id: r_id }) => l_id == r_id,
(_, _) => false,
}
self.id == other.id && self.counter == other.counter
}
}
impl Eq for PlayingNode {}
impl Eq for RedNode {}
impl Hash for PlayingNode {
impl Hash for RedNode {
fn hash<H>(&self, state: &mut H)
where
H: std::hash::Hasher,
{
self.id().hash(state);
self.id.hash(state);
}
}
pub type Nodes = Vec<String>;
pub type Predecessors = HashMap<String, HashSet<PlayingNode>>;
pub type Predecessors = HashMap<String, HashSet<RedNode>>;
pub type Successors = HashMap<String, HashSet<String>>;
pub type WinningPositions = HashSet<String>;
pub type AdditionalWinning = HashSet<String>;
......@@ -67,16 +45,15 @@ fn insert_node(node: String, additional_winning: &mut AdditionalWinning, pred: &
predecessors.and_modify(|predecessors| {
let mut changed_predecessors = HashSet::new();
for predecessor in predecessors.iter() {
if let PlayingNode::Red { id, counter } = predecessor {
let counter = counter - 1;
if counter == 0 {
to_insert.push(id.clone());
} else {
changed_predecessors.insert(PlayingNode::Red {
id: id.clone(),
counter,
});
}
let RedNode { id, counter } = predecessor;
let counter = counter - 1;
if counter == 0 {
to_insert.push(id.clone());
} else {
changed_predecessors.insert(RedNode {
id: id.clone(),
counter,
});
}
}
*predecessors = changed_predecessors
......
......@@ -98,19 +98,15 @@ 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 {
let pre_node = if reds.contains(predecessor) {
PlayingNode::Red {
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());
}
} else {
PlayingNode::Green {
id: predecessor.clone(),
}
};
for successor in successors {
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