@@ -115,11 +115,11 @@ def astar_search(g, position, ur):
115
115
116
116
# One row in the table means one graph, but some rows are different but have same edges to remove because some different nodes may locate in the same
117
117
# edge, so the length of final graph list may longer than the table
118
- def VeSpAGraphGenerator (table , nodes_group_list , vcofe , g ):
118
+ def VespaGraphGenerator (table , nodes_group_list , vcofe , g ):
119
119
g_list = []
120
120
edge_remove_listall = []
121
121
for row in table :
122
- g_VeSpA = g .copy ()
122
+ g_Vespa = g .copy ()
123
123
edge_remove_list = []
124
124
# cut the edges when there are valves onside be set to 0 in a row
125
125
for i in range (len (row )):
@@ -153,10 +153,10 @@ def VeSpAGraphGenerator(table, nodes_group_list, vcofe, g):
153
153
continue
154
154
# remove edges involved
155
155
for e in edge_remove_list :
156
- for edge in g_VeSpA .edges ():
156
+ for edge in g_Vespa .edges ():
157
157
if Counter (e ) == Counter (edge ):
158
- g_VeSpA .remove_edge (e [0 ], e [1 ])
159
- g_list .append (g_VeSpA )
158
+ g_Vespa .remove_edge (e [0 ], e [1 ])
159
+ g_list .append (g_Vespa )
160
160
edge_remove_listall .append (edge_remove_list )
161
161
return g_list
162
162
@@ -166,55 +166,82 @@ def VeSpAGraphGenerator(table, nodes_group_list, vcofe, g):
166
166
# All node[0] node[1] here will be totally same or different at all. If they have intersection node, they will be
167
167
# connected by the findallConnectedNodes() function. So, we can transfer the current d to a list of tuples consists
168
168
# of two node groups, all nodes in the group should be open or close together.
169
- def enumerateVeSpAgraphs (g , d , vcofe , listlen ):
170
- conflict = 0
169
+ def enumerateVespagraphs (g , d , vcofe , listlen ):
170
+
171
171
# creat node group constraint list
172
172
conflict , ConstraintNGList , nodes_group_list = Node_NG_Constraint_translater (d )
173
173
if conflict == 1 :
174
174
return 1 , []
175
175
# create a truth table including all node groups according to the ConstraintGroupList
176
- conflict , table , fp = NodeGroupTruthTableBuilder (nodes_group_list , ConstraintNGList , listlen )
177
- I_best = len (table )
176
+ conflict , table , NotAllGraph = NodeGroupTruthTableBuilder (nodes_group_list , ConstraintNGList , listlen )
177
+ NumOfGraph = len (table )
178
178
# Use the table to generate graphs which lose some edges compared with the original graph.
179
- g_list = VeSpAGraphGenerator (table , nodes_group_list , vcofe , g )
180
- return conflict , g_list , fp , I_best
179
+ g_list = VespaGraphGenerator (table , nodes_group_list , vcofe , g )
180
+ return conflict , g_list , NotAllGraph , NumOfGraph
181
+
181
182
183
+ def get_ports (G ):
184
+ ports = []
185
+ for node in G :
186
+ if 'o' not in node :
187
+ ports .append (node )
188
+ return ports
182
189
183
- def VeSpA_search (g , g_c , position , ConstraintList , VCO2FEdictionary , ur , listlen ):
190
+
191
+ def Vespa_search (g , g_c , position , ConstraintList , VCO2FEdictionary , ur , listlen ):
184
192
global pos
185
193
pos = position
186
194
start = time .time ()
195
+ ports = get_ports (g )
196
+ leakage_fail = 0
187
197
188
198
# Create a constraint dictionary list represents the constraint equation:
189
199
# Data structure: {'Type': 2, 'TruthTable': [[0, 0]], 'Nodes': [['co1'...], ['co3'...]]}
190
- Conflict , NGConstraintDict = NodeGroupConstraintDictBuilder (ConstraintList , g , g_c )
200
+ Conflict , NGConstraintDict = NodeGroupConstraintDictBuilder (ConstraintList , g_c )
191
201
192
202
# update graph with removing the edges in constraint type 1
193
203
g , NGConstraintDictNew = updateGraphByNGConstraint (VCO2FEdictionary , g , NGConstraintDict )
194
204
# generate all graphs satisfy the constraint type 2 as a list
195
- Conflict , g_list , flagFalseNegative , I_best = enumerateVeSpAgraphs (g , NGConstraintDictNew , VCO2FEdictionary , listlen )
205
+ Conflict , g_list , NotAllGraph , NumOfGraph = enumerateVespagraphs (g , NGConstraintDictNew , VCO2FEdictionary , listlen )
196
206
if Conflict == 1 :
197
- print ("Constraint conflict 2 !" , ConstraintList )
207
+ print ("Constraint conflict!" , ConstraintList )
198
208
end = time .time ()
199
- return end - start , [], - 2 , - 1 , I_best
200
- VeSpAPathMin = []
201
- VeSpALengthMin = 0
209
+ return end - start , [], - 2 , - 1 , NumOfGraph , leakage_fail
210
+ VespaPathMin = []
211
+ VespaLengthMin = 0
202
212
# If the list is too big, we can randomly choose 1000 graphs from the big list to speedup the procedure. (random way)
203
213
# Here we choose graphs in order from truth table elements are all 1 to all 0. (Our way)
204
214
# if len(g_list) > listlen:
205
215
# flagFalseNegative = 1
206
216
# g_list = random.sample(g_list, listlen)
207
217
for gb in g_list :
208
- _ , VeSpAPath , VeSpALength = netxsp_search (gb , ur )
209
- if len (VeSpAPathMin ) == 0 or VeSpALengthMin > VeSpALength > 0 :
210
- VeSpAPathMin = VeSpAPath
211
- VeSpALengthMin = VeSpALength
218
+ _ , VespaPath , VespaLength = netxsp_search (gb , ur )
219
+ if len (VespaPathMin ) == 0 or VespaLengthMin > VespaLength > 0 :
220
+ if VespaLength > 0 :
221
+ flag_leakage = False
222
+ for p in ports :
223
+ if p in ur [0 ]:
224
+ continue
225
+ ur_new = [ur [0 ], p ]
226
+ _ , _ , l = netxsp_search (gb , ur_new )
227
+
228
+ # leakage issue arise
229
+ if l > 0 :
230
+ if p not in ur [1 ]:
231
+ flag_leakage = True
232
+ break
233
+ # if current graph have leakage issue, skip it
234
+ if flag_leakage :
235
+ leakage_fail += 1
236
+ continue
237
+ VespaPathMin = VespaPath
238
+ VespaLengthMin = VespaLength
212
239
end = time .time ()
213
- if not VeSpAPathMin :
214
- # print(f"No such a path from {ur[0]} to {ur[1]} using VeSpA I={listlen} searching algorithm")
215
- return end - start , [], - 1 , flagFalseNegative , I_best
216
- VeSpATime = end - start
217
- return VeSpATime , VeSpAPathMin , VeSpALengthMin , flagFalseNegative , I_best
240
+ if not VespaPathMin :
241
+ # print(f"No such a path from {ur[0]} to {ur[1]} using Vespa I={listlen} searching algorithm")
242
+ return end - start , [], - 1 , NotAllGraph , NumOfGraph , leakage_fail
243
+ VespaTime = end - start
244
+ return VespaTime , VespaPathMin , VespaLengthMin , NotAllGraph , NumOfGraph , leakage_fail
218
245
219
246
220
247
def control_search (path , dictionary ):
@@ -275,8 +302,8 @@ def simulateControlPathway(time, path, filepath, j, graph, GraphListInfo):
275
302
pass
276
303
277
304
278
- def simulate (NodeInfo , NetxSPTime , NetxSPPath , NCP , DijkstraTime , DijkstraPath , DCP , AstarTime , AstarPath , ACP , VeSpATime ,
279
- VeSpAPath , BCP , i , j , g , g_c , gli ):
305
+ def simulate (NodeInfo , NetxSPTime , NetxSPPath , NCP , DijkstraTime , DijkstraPath , DCP , AstarTime , AstarPath , ACP , VespaTime ,
306
+ VespaPath , BCP , i , j , g , g_c , gli ):
280
307
# NetxSP simulate flow pathway
281
308
outputfolderpath = f"TestCaseFiles/NetxSP_result/Section_{ i } /{ NodeInfo } "
282
309
simulateFlowPathway (NetxSPTime , NetxSPPath , outputfolderpath , j , g , gli )
@@ -289,9 +316,9 @@ def simulate(NodeInfo, NetxSPTime, NetxSPPath, NCP, DijkstraTime, DijkstraPath,
289
316
outputfolderpath = f"TestCaseFiles/A*_result/Section_{ i } /{ NodeInfo } "
290
317
simulateFlowPathway (AstarTime , AstarPath , outputfolderpath , j , g , gli )
291
318
292
- # VeSpA simulate flow pathway
293
- outputfolderpath = f"TestCaseFiles/VeSpA_result /Section_{ i } /{ NodeInfo } "
294
- simulateFlowPathway (VeSpATime , VeSpAPath , outputfolderpath , j , g , gli )
319
+ # Vespa simulate flow pathway
320
+ outputfolderpath = f"TestCaseFiles/Vespa_result /Section_{ i } /{ NodeInfo } "
321
+ simulateFlowPathway (VespaTime , VespaPath , outputfolderpath , j , g , gli )
295
322
296
323
# NetxSP simulate control layer pathway
297
324
outputfolderpath = f"TestCaseFiles/NetxSP_result/Section_{ i } /{ NodeInfo } "
@@ -305,6 +332,6 @@ def simulate(NodeInfo, NetxSPTime, NetxSPPath, NCP, DijkstraTime, DijkstraPath,
305
332
outputfolderpath = f"TestCaseFiles/A*_result/Section_{ i } /{ NodeInfo } "
306
333
simulateControlPathway (AstarTime , AstarPath , outputfolderpath , j , g , gli )
307
334
308
- # VeSpA simulate control pathway
309
- outputfolderpath = f"TestCaseFiles/VeSpA_result /Section_{ i } /{ NodeInfo } "
310
- simulateControlPathway (VeSpATime , VeSpAPath , outputfolderpath , j , g , gli )
335
+ # Vespa simulate control pathway
336
+ outputfolderpath = f"TestCaseFiles/Vespa_result /Section_{ i } /{ NodeInfo } "
337
+ simulateControlPathway (VespaTime , VespaPath , outputfolderpath , j , g , gli )
0 commit comments