@@ -121,6 +121,18 @@ def _vb(msg):
121
121
_vb (" Begin epoch" )
122
122
scenario_cycler .begin_epoch ()
123
123
124
+ # always try at least two for each set of nonants
125
+ # so we continue to explore the scenarios and
126
+ # do not stall out on a single scenario because
127
+ # the hub is moving very fast
128
+ next_scendict = scenario_cycler .get_next ()
129
+ if next_scendict is not None :
130
+ _vb (f" Trying next { next_scendict } " )
131
+ update = self .try_scenario_dict (next_scendict )
132
+ if update :
133
+ _vb (f" Updating best to { next_scendict } " )
134
+ scenario_cycler .best = next_scendict ["ROOT" ]
135
+
124
136
next_scendict = scenario_cycler .get_next ()
125
137
if next_scendict is not None :
126
138
_vb (f" Trying next { next_scendict } " )
@@ -140,13 +152,14 @@ def __init__(self, shuffled_scenarios,nonleaves,reverse,iter_step):
140
152
root_kids = nonleaves ['ROOT' ].kids if 'ROOT' in nonleaves else None
141
153
if root_kids is None or len (root_kids )== 0 or root_kids [0 ].is_leaf :
142
154
self ._multi = False
143
- self ._iter_shift = 1 if iter_step is None else iter_step
155
+ self ._iter_shift = 0 if iter_step is None else iter_step
144
156
self ._use_reverse = False #It is useless to reverse for 2stage SP
145
157
else :
146
158
self ._multi = True
147
159
self .BF0 = len (root_kids )
148
160
self ._nonleaves = nonleaves
149
-
161
+ # TODO: is this right for multistage, or should the default be
162
+ # 0 like in the two-stage case?
150
163
self ._iter_shift = self .BF0 if iter_step is None else iter_step
151
164
self ._use_reverse = True if reverse is None else reverse
152
165
self ._reversed = False #Do we iter in reverse mode ?
@@ -189,7 +202,7 @@ def _add_sname_to_node(ndn):
189
202
filling_idx += 1
190
203
filling_idx %= self ._num_scenarios
191
204
192
- def create_nodescen_dict (self ):
205
+ def _create_nodescen_dict (self ):
193
206
'''
194
207
Creates an attribute nodescen_dict.
195
208
Keys are nonleaf names, values are local scenario names
@@ -203,7 +216,7 @@ def create_nodescen_dict(self):
203
216
self .nodescen_dict = dict ()
204
217
self ._fill_nodescen_dict (self ._nonleaves .keys ())
205
218
206
- def update_nodescen_dict (self ,snames_to_remove ):
219
+ def _update_nodescen_dict (self ,snames_to_remove ):
207
220
'''
208
221
WARNING: _cur_ROOTscen must be up to date when calling this method
209
222
'''
@@ -230,7 +243,7 @@ def _begin_normal_epoch(self):
230
243
self ._shuffled_snames = [s [1 ] for s in self ._shuffled_scenarios ]
231
244
self ._original_order = [s [0 ] for s in self ._shuffled_scenarios ]
232
245
self ._cur_ROOTscen = self ._shuffled_snames [0 ] if self .best is None else self .best
233
- self .create_nodescen_dict ()
246
+ self ._create_nodescen_dict ()
234
247
235
248
self ._scenarios_this_epoch = set ()
236
249
@@ -239,7 +252,7 @@ def _begin_reverse_epoch(self):
239
252
self ._shuffled_snames = [s [1 ] for s in reversed (self ._shuffled_scenarios )]
240
253
self ._original_order = [s [0 ] for s in reversed (self ._shuffled_scenarios )]
241
254
self ._cur_ROOTscen = self ._shuffled_snames [0 ] if self .best is None else self .best
242
- self .create_nodescen_dict ()
255
+ self ._create_nodescen_dict ()
243
256
244
257
self ._scenarios_this_epoch = set ()
245
258
@@ -270,9 +283,9 @@ def _iter_scen(self):
270
283
#Updating scenarios
271
284
self ._cur_ROOTscen = self ._shuffled_snames [self ._cycle_idx ]
272
285
if old_idx < self ._cycle_idx :
273
- scens_to_remove = self ._shuffled_snames [old_idx :self ._cycle_idx ]
286
+ scens_to_remove = set ( self ._shuffled_snames [old_idx :self ._cycle_idx ])
274
287
else :
275
- scens_to_remove = self ._shuffled_snames [old_idx :]+ self ._shuffled_snames [:self ._cycle_idx ]
276
- self .update_nodescen_dict (scens_to_remove )
288
+ scens_to_remove = set ( self ._shuffled_snames [old_idx :]+ self ._shuffled_snames [:self ._cycle_idx ])
289
+ self ._update_nodescen_dict (scens_to_remove )
277
290
278
291
0 commit comments