Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
A
automata-logic-project2
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
User expired
automata-logic-project2
Commits
93a36dce
Commit
93a36dce
authored
3 years ago
by
Valerian Wintner
Browse files
Options
Downloads
Patches
Plain Diff
Fix: Counter not shared.
parent
d86380cd
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
data/lecture.svg
+4
-4
4 additions, 4 deletions
data/lecture.svg
data/lecture_solved.svg
+4
-4
4 additions, 4 deletions
data/lecture_solved.svg
src/arena.rs
+10
-10
10 additions, 10 deletions
src/arena.rs
src/main.rs
+24
-11
24 additions, 11 deletions
src/main.rs
with
42 additions
and
29 deletions
data/lecture.svg
+
4
−
4
View file @
93a36dce
...
...
@@ -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->2 -->
<g
id=
"edge
6
"
class=
"edge"
>
<g
id=
"edge
8
"
class=
"edge"
>
<title>
1
->
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->6 -->
<g
id=
"edge
7
"
class=
"edge"
>
<g
id=
"edge
9
"
class=
"edge"
>
<title>
1
->
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->1 -->
<g
id=
"edge
8
"
class=
"edge"
>
<g
id=
"edge
7
"
class=
"edge"
>
<title>
2
->
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->3 -->
<g
id=
"edge
9
"
class=
"edge"
>
<g
id=
"edge
6
"
class=
"edge"
>
<title>
2
->
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"
/>
...
...
This diff is collapsed.
Click to expand it.
data/lecture_solved.svg
+
4
−
4
View file @
93a36dce
...
...
@@ -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->2 -->
<g
id=
"edge
6
"
class=
"edge"
>
<g
id=
"edge
8
"
class=
"edge"
>
<title>
1
->
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->6 -->
<g
id=
"edge
7
"
class=
"edge"
>
<g
id=
"edge
9
"
class=
"edge"
>
<title>
1
->
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->1 -->
<g
id=
"edge
8
"
class=
"edge"
>
<g
id=
"edge
7
"
class=
"edge"
>
<title>
2
->
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->3 -->
<g
id=
"edge
9
"
class=
"edge"
>
<g
id=
"edge
6
"
class=
"edge"
>
<title>
2
->
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"
/>
...
...
This diff is collapsed.
Click to expand it.
src/arena.rs
+
10
−
10
View file @
93a36dce
...
...
@@ -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
...
...
This diff is collapsed.
Click to expand it.
src/main.rs
+
24
−
11
View file @
93a36dce
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
());
}
}
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment