@@ -3,7 +3,7 @@ use crate::flow;
33use crate :: graph:: Graph ;
44use crate :: ideal:: Ideal ;
55use crate :: nfa;
6- use crate :: semigroup;
6+ use crate :: semigroup:: { self , FlowSemigroup } ;
77use crate :: solution:: Solution ;
88use crate :: strategy:: Strategy ;
99use clap:: ValueEnum ;
@@ -26,7 +26,7 @@ pub fn solve(nfa: &nfa::Nfa, output: &SolverOutput) -> Solution {
2626 let final_states = nfa. final_states ( ) ;
2727 let edges = nfa. get_edges ( ) ;
2828 let letters = nfa. get_alphabet ( ) ;
29- let strategy = match output {
29+ let ( strategy, semigroup ) = match output {
3030 SolverOutput :: Strategy => {
3131 compute_maximal_winning_strategy ( dim, & final_states, edges, & letters)
3232 }
@@ -39,6 +39,7 @@ pub fn solve(nfa: &nfa::Nfa, output: &SolverOutput) -> Solution {
3939 nfa : nfa. clone ( ) ,
4040 is_controllable,
4141 winning_strategy : strategy,
42+ semigroup,
4243 }
4344}
4445
@@ -47,7 +48,7 @@ fn compute_maximal_winning_strategy(
4748 final_states : & [ usize ] ,
4849 edges : HashMap < String , Graph > ,
4950 letters : & [ & str ] ,
50- ) -> Strategy {
51+ ) -> ( Strategy , FlowSemigroup ) {
5152 let maximal_finite_value = dim as coef ;
5253
5354 let mut strategy = Strategy :: get_maximal_strategy ( dim, letters) ;
@@ -58,7 +59,7 @@ fn compute_maximal_winning_strategy(
5859 info ! ( "Computing the maximal winning strategy step {}" , step) ;
5960 step += 1 ;
6061
61- let changed = update_strategy (
62+ let ( changed, semigroup ) = update_strategy (
6263 dim,
6364 & mut strategy,
6465 final_states,
@@ -67,10 +68,9 @@ fn compute_maximal_winning_strategy(
6768 ) ;
6869
6970 if !changed {
70- break ;
71+ return ( strategy , semigroup ) ;
7172 }
7273 }
73- strategy
7474}
7575
7676fn compute_control_problem_solution (
@@ -79,8 +79,9 @@ fn compute_control_problem_solution(
7979 final_states : & [ usize ] ,
8080 edges : HashMap < String , Graph > ,
8181 letters : & [ & str ] ,
82- ) -> Strategy {
82+ ) -> ( Strategy , FlowSemigroup ) {
8383 let mut strategy = Strategy :: get_maximal_strategy ( dim, letters) ;
84+ let mut semigroup = FlowSemigroup :: new ( ) ;
8485
8586 for maximal_finite_value in 1 ..dim as coef {
8687 let mut step = 1 ;
@@ -92,13 +93,14 @@ fn compute_control_problem_solution(
9293 ) ;
9394 step += 1 ;
9495
95- let changed = update_strategy (
96+ let ( changed, new_semigroup ) = update_strategy (
9697 dim,
9798 & mut strategy,
9899 final_states,
99100 & edges,
100101 maximal_finite_value,
101102 ) ;
103+ semigroup = new_semigroup;
102104 let result = strategy. is_defined_on ( source) ;
103105
104106 if !changed || !result {
@@ -109,7 +111,7 @@ fn compute_control_problem_solution(
109111 break ;
110112 }
111113 }
112- strategy
114+ ( strategy, semigroup )
113115}
114116
115117fn update_strategy (
@@ -118,7 +120,7 @@ fn update_strategy(
118120 final_states : & [ usize ] ,
119121 edges : & HashMap < String , Graph > ,
120122 maximal_finite_value : u8 ,
121- ) -> bool {
123+ ) -> ( bool , FlowSemigroup ) {
122124 let final_ideal = get_omega_ideal ( dim, final_states) ;
123125 let action_flows = compute_action_flows ( strategy, edges) ;
124126 debug ! ( "\n Action flows:\n {}" , flows_to_string( & action_flows) ) ;
@@ -137,7 +139,7 @@ fn update_strategy(
137139 debug ! ( "Restricting strategy" ) ;
138140 let changed = strategy. restrict_to ( winning_downset, edges, maximal_finite_value) ;
139141 debug ! ( "Strategy after restriction:\n {}" , strategy) ;
140- changed
142+ ( changed, semigroup )
141143}
142144
143145fn get_omega_ideal ( dim : usize , states : & [ usize ] ) -> Ideal {
0 commit comments