1010from .entity_class import EntityClass
1111from .explicit_ats import ExplicitAts , TimeType
1212from .model_info import ModelInfo
13- from .variable_valuations import EntityClassValuations , EntityValuations
1413
1514
1615def explicit_umb_to_explicit_ats (umb : umbi .umb .ExplicitUmb ) -> ExplicitAts :
@@ -36,13 +35,10 @@ def explicit_umb_to_explicit_ats(umb: umbi.umb.ExplicitUmb) -> ExplicitAts:
3635 ts = umb .index .transition_system
3736 ats .time = TimeType (ts .time )
3837 ats .num_players = ts .num_players
39- ats .num_initial_states = ts .num_initial_states
40- ats .num_choice_actions = ts .num_choice_actions
41- ats .num_branch_actions = ts .num_branch_actions
4238 ats .player_to_name = ts .player_to_name
4339
4440 ## values
45- ats .state_is_initial = umb .state_is_initial
41+ ats .set_state_is_initial ( umb .state_is_initial )
4642 ats .state_to_player = umb .state_to_player
4743
4844 ats .state_is_markovian = umb .state_is_markovian
@@ -55,6 +51,20 @@ def explicit_umb_to_explicit_ats(umb: umbi.umb.ExplicitUmb) -> ExplicitAts:
5551 state_to_choices = (
5652 umb .state_to_choices if umb .state_to_choices is not None else [s for s in range (ats .num_states + 1 )]
5753 )
54+ have_choice_actions = ts .num_choice_actions > 0
55+ if have_choice_actions :
56+ assert umb .choice_to_choice_action is not None , "num_choice_actions > 0 but choice_to_choice_action is None"
57+ ats .add_choice_actions (num_actions = ts .num_choice_actions )
58+ if umb .choice_action_to_string is not None :
59+ ats .choice_actions .set_names (umb .choice_action_to_string )
60+ have_branch_actions = ts .num_branch_actions > 0
61+ if have_branch_actions :
62+ assert umb .branch_to_branch_action is not None , "num_branch_actions > 0 but branch_to_branch_action is None"
63+ ats .add_branch_actions (num_actions = ts .num_branch_actions )
64+ if umb .branch_action_to_string is not None :
65+ ats .branch_actions .set_names (umb .branch_action_to_string )
66+
67+ branch_index = 0
5868 if ts .num_choices > 0 :
5969 for state in ats .states :
6070 for choice_idx in range (state_to_choices [state ], state_to_choices [state + 1 ]):
@@ -65,18 +75,12 @@ def explicit_umb_to_explicit_ats(umb: umbi.umb.ExplicitUmb) -> ExplicitAts:
6575 assert umb .branch_to_target is not None , "num_branches > 0 but branch_to_target is None"
6676 target = umb .branch_to_target [branch_idx ]
6777 prob = umb .branch_to_probability [branch_idx ] if umb .branch_to_probability is not None else None
68- branch_action = (
69- umb .branch_to_branch_action [branch_idx ] if umb .branch_to_branch_action is not None else None
70- )
71- choice .add_branch (target = target , prob = prob , action = branch_action )
72- if ts .num_choice_actions > 0 :
73- assert umb .choice_to_choice_action is not None , (
74- "num_choice_actions > 0 but choice_to_choice_action is None"
75- )
76- choice .action = umb .choice_to_choice_action [choice_idx ]
77-
78- ats .choice_action_to_name = umb .choice_action_to_string
79- ats .branch_action_to_name = umb .branch_action_to_string
78+ choice .add_branch (target = target , prob = prob )
79+ branch_index += 1 # TODO make ats.add_branch return the branch index
80+ if have_branch_actions :
81+ ats .branch_actions [branch_index ] = umb .branch_to_branch_action [branch_idx ] # type: ignore[subscript]
82+ if have_choice_actions :
83+ ats .choice_actions [choice .index ] = umb .choice_to_choice_action [choice_idx ] # type: ignore[subscript]
8084
8185 # load annotations
8286 if umb .index .annotations is not None :
@@ -102,7 +106,7 @@ def explicit_umb_to_explicit_ats(umb: umbi.umb.ExplicitUmb) -> ExplicitAts:
102106 # load valuations
103107 if umb .index .valuations is not None :
104108 assert umb .valuations is not None
105- ats .variable_valuations = EntityClassValuations ()
109+ ats .add_variable_valuations ()
106110 for applies_to , valuation_description in umb .index .valuations .items ():
107111 # ignore unique and num_strings
108112 # assume a single valuation class
@@ -112,7 +116,7 @@ def explicit_umb_to_explicit_ats(umb: umbi.umb.ExplicitUmb) -> ExplicitAts:
112116
113117 entity_to_valuation = umb .valuations [applies_to ]
114118 entity_class = EntityClass (applies_to )
115- entity_valuations = EntityValuations ( )
119+ entity_valuations = ats . variable_valuations . add_valuations_for ( entity_class )
116120 for attribute in struct_type .attributes :
117121 if attribute .lower is not None or attribute .upper is not None :
118122 raise NotImplementedError ("bounds on valuation variables not supported yet" )
@@ -122,7 +126,6 @@ def explicit_umb_to_explicit_ats(umb: umbi.umb.ExplicitUmb) -> ExplicitAts:
122126 for entity , valuation in enumerate (entity_to_valuation ):
123127 valuation = {entity_valuations .get_variable (var_name ): value for var_name , value in valuation .items ()}
124128 entity_valuations .set_entity_valuation (entity , valuation )
125- ats .variable_valuations .set_valuations_for (entity_class , entity_valuations )
126129
127130 # load observations
128131 if ts .observations_apply_to is not None :
@@ -167,9 +170,9 @@ def explicit_ats_to_explicit_umb(ats: ExplicitAts) -> umbi.umb.ExplicitUmb:
167170 num_states = ats .num_states ,
168171 num_initial_states = ats .num_initial_states ,
169172 num_choices = ats .num_choices ,
170- num_choice_actions = ats . num_choice_actions ,
173+ num_choice_actions = 0 , # for now
171174 num_branches = ats .num_branches ,
172- num_branch_actions = ats . num_branch_actions ,
175+ num_branch_actions = 0 , # for now
173176 num_observations = ats .num_observations ,
174177 observations_apply_to = None , # for now
175178 branch_probability_type = None , # for now
@@ -185,7 +188,7 @@ def explicit_ats_to_explicit_umb(ats: ExplicitAts) -> umbi.umb.ExplicitUmb:
185188 ## values
186189 # warning: this does not copy the values, but directly uses the lists from ats.
187190 # this is fine as long as we don't modify them
188- umb .state_is_initial = ats .state_is_initial
191+ umb .state_is_initial = list ( ats .state_is_initial )
189192 umb .state_to_player = ats .state_to_player
190193
191194 umb .state_is_markovian = ats .state_is_markovian
@@ -204,8 +207,11 @@ def explicit_ats_to_explicit_umb(ats: ExplicitAts) -> umbi.umb.ExplicitUmb:
204207 umb .state_to_choices .append (num_choices )
205208
206209 if ats .num_choices > 0 :
207- if ats .num_choice_actions > 0 :
208- umb .choice_to_choice_action = [choice .action for choice in ats .choices ] # type: ignore
210+ if ats .has_choice_actions > 0 :
211+ umb .index .transition_system .num_choice_actions = ats .choice_actions .num_actions
212+ umb .choice_to_choice_action = list (ats .choice_actions .values )
213+ if ats .choice_actions .has_names :
214+ umb .choice_action_to_string = list (ats .choice_actions .names )
209215
210216 branches = []
211217 umb .choice_to_branches = []
@@ -223,14 +229,11 @@ def explicit_ats_to_explicit_umb(ats: ExplicitAts) -> umbi.umb.ExplicitUmb:
223229 # assert isinstance(target_type, umbi.datatypes.NumericType), "branch probabilities must be numeric"
224230 umb .index .transition_system .branch_probability_type = SizedType .for_type (target_type )
225231 umb .branch_to_probability = vector # type: ignore
226- if ats .num_branch_actions > 0 :
227- branch_actions = [branch .action for branch in branches ]
228- if any (action is None for action in branch_actions ):
229- raise ValueError ("if num_branch_actions > 0, all branches must have an action" )
230- umb .branch_to_branch_action = branch_actions # type: ignore
231-
232- umb .choice_action_to_string = ats .choice_action_to_name
233- umb .branch_action_to_string = ats .branch_action_to_name
232+ if ats .has_branch_actions :
233+ umb .index .transition_system .num_branch_actions = ats .branch_actions .num_actions
234+ umb .branch_to_branch_action = list (ats .branch_actions .values )
235+ if ats .branch_actions .has_names :
236+ umb .branch_action_to_string = list (ats .branch_actions .names )
234237
235238 # add annotations
236239 umb .index .annotations = {}
0 commit comments