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
46bf4fb8
Commit
46bf4fb8
authored
3 years ago
by
Valerian Wintner
Browse files
Options
Downloads
Patches
Plain Diff
svg output of graph, also version with winning positions
parent
5e2a3ad3
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
src/arena.rs
+7
-6
7 additions, 6 deletions
src/arena.rs
src/lecture.dot
+3
-2
3 additions, 2 deletions
src/lecture.dot
src/main.rs
+110
-51
110 additions, 51 deletions
src/main.rs
with
120 additions
and
59 deletions
src/arena.rs
+
7
−
6
View file @
46bf4fb8
...
...
@@ -67,7 +67,7 @@ fn insert_node(node: String, additional_winning: &mut AdditionalWinning, pred: &
pub
fn
pre
(
greens
:
Nodes
,
winning_positions
:
&
WinningPositions
,
succ
:
&
mut
Successors
,
succ
:
&
Successors
,
pred
:
&
mut
Predecessors
,
)
->
(
Nodes
,
AdditionalWinning
)
{
let
mut
additional_winning
:
AdditionalWinning
=
HashSet
::
new
();
...
...
@@ -86,15 +86,16 @@ pub fn pre(
(
remaining_greens
,
additional_winning
)
}
pub
fn
winning_positions
(
mut
greens
:
Nodes
,
final_positions
:
WinningPositions
,
mut
succ
:
Successors
,
greens
:
&
Nodes
,
final_positions
:
&
WinningPositions
,
succ
:
&
Successors
,
mut
pred
:
Predecessors
,
)
->
WinningPositions
{
let
mut
greens
=
greens
.clone
();
let
mut
winning_positions
=
HashSet
::
new
();
// Insert the final positions as winning positions. Separate step, due to changing the counter of the red nodes being necessary.
for
winner
in
final_positions
{
insert_node
(
winner
,
&
mut
winning_positions
,
&
mut
pred
);
insert_node
(
winner
.to_string
()
,
&
mut
winning_positions
,
&
mut
pred
);
}
// dbg!(&winning_positions, &pred);
// Remove green nodes that have already been added to winners due to being final positions
...
...
@@ -105,7 +106,7 @@ pub fn winning_positions(
// Do the pre-loop, that extends the winning set and shrinks the green-node-vector in each iteration.
loop
{
let
(
changed_greens
,
additional_winnings
)
=
pre
(
greens
,
&
winning_positions
,
&
mut
succ
,
&
mut
pred
);
pre
(
greens
,
&
winning_positions
,
&
succ
,
&
mut
pred
);
if
additional_winnings
.is_empty
()
{
return
winning_positions
;
}
...
...
This diff is collapsed.
Click to expand it.
src/lecture.dot
+
3
−
2
View file @
46bf4fb8
digraph
sample
{
digraph
lecture
{
rankdir
=
LR
1
[
player
=
red
]
2
[
player
=
green
]
3
[
player
=
red
]
4
[
player
=
green
]
5
[
player
=
red
,
state
=
final
]
6
[
player
=
green
,
state
=
final
]
6
[
player
=
green
,
state
=
final
,
label
=
asdasd
]
1
->
2
->
3
->
4
->
5
2
->
1
->
6
->
6
4
->
3
->
5
...
...
This diff is collapsed.
Click to expand it.
src/main.rs
+
110
−
51
View file @
46bf4fb8
...
...
@@ -4,6 +4,7 @@ use std::collections::{HashMap, HashSet};
use
std
::
env
;
use
std
::
fs
::{
self
,
File
};
use
std
::
io
::{
Read
,
Write
};
use
std
::
rc
::
Rc
;
use
dot_generator
::
*
;
use
dot_structures
::
*
;
...
...
@@ -24,17 +25,20 @@ fn main() {
dbg!
(
&
input
);
let
g
=
parse
(
&
input
)
.unwrap
();
// let g2 = change_graph(&g);
let
(
greens
,
reds
,
final_positions
,
succ
,
pred
)
=
build_inputs
(
&
g
);
// dbg!(greens, reds, final_positions, succ, pred);
let
winners
=
arena
::
winning_positions
(
greens
,
final_positions
,
succ
,
pred
);
let
winners
=
arena
::
winning_positions
(
&
greens
,
&
final_positions
,
&
succ
,
pred
);
let
g2
=
build_graph
(
&
greens
,
&
reds
,
&
final_positions
,
&
succ
,
Some
(
&
winners
));
println!
(
"{}"
,
g2
.print
(
&
mut
PrinterContext
::
default
()));
dbg!
(
winners
);
//
output(&g2);
output
(
&
g2
);
}
fn
node_id
(
node
:
&
Node
)
->
&
String
{
...
...
@@ -110,15 +114,110 @@ fn build_inputs(g: &Graph) -> (Nodes, Nodes, WinningPositions, Successors, Prede
}
}
}
(
greens
.into_iter
()
.collect
(),
reds
.into_iter
()
.collect
(),
final_positions
,
succ
,
pred
,
)
let
mut
greens
:
Vec
<
String
>
=
greens
.into_iter
()
.collect
();
greens
.sort
();
let
mut
reds
:
Vec
<
String
>
=
reds
.into_iter
()
.collect
();
reds
.sort
();
(
greens
,
reds
,
final_positions
,
succ
,
pred
)
}
enum
Colour
{
Red
,
Green
,
}
fn
build_graph
(
reds
:
&
Nodes
,
greens
:
&
Nodes
,
finals
:
&
WinningPositions
,
succ
:
&
Successors
,
winning_positions
:
Option
<&
WinningPositions
>
,
)
->
Graph
{
let
mut
stmts
=
Vec
::
new
();
let
reds
=
reds
.iter
()
.map
(|
r
|
(
r
.clone
(),
Colour
::
Red
));
let
greens
=
greens
.iter
()
.map
(|
g
|
(
g
.clone
(),
Colour
::
Green
));
let
mut
nodes
=
reds
.chain
(
greens
)
.collect
::
<
Vec
<
(
String
,
Colour
)
>>
();
nodes
.sort_by_key
(|
c
|
c
.0
.clone
());
for
(
id
,
colour
)
in
nodes
{
let
is_winning
=
if
let
Some
(
winning_positions
)
=
winning_positions
{
winning_positions
.contains
(
&
id
)
}
else
{
false
};
let
node
=
match
colour
{
Colour
::
Red
=>
{
let
mut
node
=
node!
(
id
;
NodeAttributes
::
shape
(
shape
::
square
),
NodeAttributes
::
fillcolor
(
if
is_winning
{
// needs ugly copy+paste here because colour does not implement clone or copy-trait
color_name
::
orange
}
else
{
color_name
::
red4
}),
NodeAttributes
::
style
(
"filled"
.to_string
()));
if
finals
.contains
(
&
id
)
{
node
.attributes
.push
(
NodeAttributes
::
peripheries
(
2
));
let
colour
=
if
is_winning
{
"
\"
orange1:white:orange1
\"
"
}
else
{
"
\"
red4:white:red4
\"
"
};
node
.attributes
.push
(
attr!
(
"color"
,
colour
));
}
else
{
node
.attributes
.push
(
NodeAttributes
::
color
(
if
is_winning
{
color_name
::
orange
}
else
{
color_name
::
red4
}));
}
node
}
Colour
::
Green
=>
{
let
mut
node
=
node!
(
id
;
NodeAttributes
::
shape
(
shape
::
diamond
),
NodeAttributes
::
fillcolor
(
if
is_winning
{
color_name
::
orange
}
else
{
color_name
::
green4
}),
NodeAttributes
::
style
(
"filled"
.to_string
()));
if
finals
.contains
(
&
id
)
{
node
.attributes
.push
(
NodeAttributes
::
peripheries
(
2
));
let
colour
=
if
is_winning
{
"
\"
orange1:white:orange1
\"
"
}
else
{
"
\"
green4:white:green4
\"
"
};
node
.attributes
.push
(
attr!
(
"color"
,
colour
));
}
else
{
node
.attributes
.push
(
NodeAttributes
::
color
(
if
is_winning
{
color_name
::
orange
}
else
{
color_name
::
green4
}));
}
node
}
};
stmts
.push
(
Stmt
::
Node
(
node
));
}
for
(
id
,
successors
)
in
succ
{
for
successor
in
successors
{
let
edge
=
edge!
(
node_id!
(
id
)
=>
node_id!
(
successor
));
stmts
.push
(
Stmt
::
Edge
(
edge
));
}
}
stmts
.push
(
Stmt
::
GAttribute
(
dot_structures
::
GraphAttributes
::
Graph
(
vec!
[
attr!
(
"rankdir"
,
"LR"
)],
)));
Graph
::
DiGraph
{
id
:
id!
(
"nice"
),
strict
:
true
,
stmts
,
}
}
fn
change_graph
(
g
:
&
Graph
)
->
Graph
{
let
(
id
,
strict
,
mut
stmts
)
=
match
g
{
Graph
::
DiGraph
{
id
,
strict
,
stmts
}
=>
(
id
.clone
(),
*
strict
,
stmts
.clone
()),
...
...
@@ -150,43 +249,3 @@ fn output(g: &Graph) {
let
mut
file
=
File
::
create
(
"out.svg"
)
.unwrap
();
file
.write_all
(
graph_svg
.as_bytes
())
.unwrap
();
}
fn
output_test
()
{
let
mut
g
=
graph!
(
strict
di
id!
(
"id"
);
node!
(
"a"
;
NodeAttributes
::
shape
(
shape
::
diamond
),
NodeAttributes
::
fillcolor
(
color_name
::
green
),
NodeAttributes
::
style
(
"filled"
.to_string
())
),
node!
(
"b"
;
NodeAttributes
::
shape
(
shape
::
square
),
NodeAttributes
::
fillcolor
(
color_name
::
red
),
NodeAttributes
::
style
(
"filled"
.to_string
())
),
node!
(
"c"
;
NodeAttributes
::
shape
(
shape
::
diamond
),
NodeAttributes
::
fillcolor
(
color_name
::
green
),
NodeAttributes
::
style
(
"filled"
.to_string
()),
NodeAttributes
::
peripheries
(
2
)
),
node!
(
"d"
;
NodeAttributes
::
shape
(
shape
::
square
),
NodeAttributes
::
fillcolor
(
color_name
::
red
),
NodeAttributes
::
style
(
"filled"
.to_string
()),
NodeAttributes
::
peripheries
(
2
)
),
edge!
(
node_id!
(
"a"
)
=>
node_id!
(
"b"
)
=>
node_id!
(
"c"
)),
edge!
(
node_id!
(
"a"
)
=>
node_id!
(
"d"
))
);
let
graph_svg
=
exec
(
g
.clone
(),
PrinterContext
::
default
(),
vec!
[
CommandArg
::
Format
(
Format
::
Svg
)],
)
.unwrap
();
println!
(
"{}"
,
print
(
g
,
PrinterContext
::
default
()));
let
mut
file
=
File
::
create
(
"out.svg"
)
.unwrap
();
file
.write_all
(
graph_svg
.as_bytes
())
.unwrap
();
}
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