Forráskód Böngészése

Update to make the code work for any type of latency

Yentl Van Tendeloo 7 éve
szülő
commit
f713d47523
3 módosított fájl, 32 hozzáadás és 15 törlés
  1. 23 2
      calibration/calibrate.py
  2. 8 12
      model/model.py
  3. 1 1
      model/operations

+ 23 - 2
calibration/calibrate.py

@@ -13,6 +13,26 @@ with open(sys.argv[1] if len(sys.argv) > 1 else "calibration/result", 'r') as f:
         except:
             pass
 
+fancy = {"read_root": "read root ID",
+         "read_dict": "read dictionary",
+         "read_dict_keys": "read dictionary keys",
+         "read_value": "read node value",
+         "read_dict_node": "read dictionary by node",
+         "rule_generation": "rule generation",
+         "read_dict_edge": "read dictionary edge",
+         "create_node": "create node",
+         "create_edge": "create edge",
+         "create_nodevalue": "create value",
+         "create_dict": "create dictionary",
+         "delete_edge": "delete edge",
+         "delete_node": "delete node",
+         "purge": "garbage collect",
+         "read_reverse_dict": "dictionary key lookup",
+         "read_outgoing": "read outgoing edges",
+         "read_incoming": "read incoming edges",
+         "read_edge": "read edge",
+         "read_dict_node_edge": "read dictionary edge by node",
+        }
 s = 0.0
 with open("calibration/averages", 'w') as averages:
     with open("calibration/plot", 'w') as plot:
@@ -41,6 +61,7 @@ with open("calibration/averages", 'w') as averages:
             plot.write("set title 'Operation %s'\n" % op.replace("_", "\\_"))
             plot.write("plot 'calibration/distribution_%s' u (rounded($1)):(1) smooth freq w boxes title ''\n" % op)
 
-            print("%s: %s x %s = %s" % (op, avg, len(operations[op]), avg * len(operations[op])))
+            #print("%s: %s x %s = %s" % (op, avg, len(operations[op]), avg * len(operations[op])))
+            print("% -23s&% -23s& %.8f\\\\" % (fancy[op], "{:,}".format(len(operations[op])), avg))
             s += avg * len(operations[op])
-print("TOTAL: " + str(s))
+#print("TOTAL: " + str(s))

+ 8 - 12
model/model.py

@@ -398,7 +398,8 @@ class ModelverseInterface(AtomicDEVS):
     def intTransition(self):
         self.state.create_additional_task = []
         if not self.state.send_operations:
-            self.state.operations.pop(0)
+            if self.state.operations[0] is not None:
+                self.state.operations.pop(0)
         else:
             for k in self.state.send_operations.keys():
                 if self.state.send_operations[k]:
@@ -409,7 +410,7 @@ class ModelverseInterface(AtomicDEVS):
 
     def extTransition(self, inputs):
         for inp in inputs[self.from_mvk]:
-            #print(inp)
+            print(inp)
             self.state.blocked = False
 
             self.state.output.setdefault(inp[0], []).append(inp[1])
@@ -429,20 +430,15 @@ class ModelverseInterface(AtomicDEVS):
                     _, task_name = prev_output.split("Spawned activity on task: ", 1)
                     self.state.blocked = True
                     self.state.task_to_spawner[task_name] = None
-                    # NOTE We now know that there is something to do on an other task, so we just wait for that event to come in
-                    self.state.operations.insert(0, None)
-                    self.state.operations.insert(0, None)
                 elif prev_output.startswith("Finished task: "):
                     self.state.blocked = True
                 elif " : " in prev_output:
                     task_name, _ = prev_output.split(" : ", 1)
                     self.state.blocked = True
                     self.state.task_to_spawner[task_name] = None
-                    # NOTE We now know that there is something to do on an other task, so we just wait for that event to come in
-                    self.state.operations.insert(0, None)
                     self.state.operations.insert(0, None)
                 elif prev_output == "Success":
-                    self.state.operations.pop(0)
+                    self.state.operations = [["echo", "FINISHED"]]
                     self.state.blocked = False
 
             elif inp[0] != self.taskname:
@@ -487,12 +483,12 @@ class ModelverseInterface(AtomicDEVS):
                 if v and v[0] is not None:
                     outp.append((k, v[0]))
             if outp:
-                #print("SEND " + str(outp))
+                print("SEND " + str(outp))
                 return {self.to_mvk: outp}
             else:
                 return {}
         elif self.state.operations and self.state.operations[0] is not None:
-            #print("SEND " + str([(self.taskname, self.state.operations[0])]))
+            print("SEND " + str([(self.taskname, self.state.operations[0])]))
             return {self.to_mvk: [(self.taskname, self.state.operations[0])]}
         else:
             return {}
@@ -743,5 +739,5 @@ if __name__ == "__main__":
         i += 2
     ts, te = simulate(args)
 
-    print("Simulation time %s" % ts)
-    print("Execution time %s" % te)
+    print("Execution time %s" % ts)
+    print("Simulation time %s" % te)

A különbségek nem kerülnek megjelenítésre, a fájl túl nagy
+ 1 - 1
model/operations