فهرست منبع

color changes

rparedis 1 سال پیش
والد
کامیت
9cd4fa35f6
8فایلهای تغییر یافته به همراه38 افزوده شده و 19 حذف شده
  1. BIN
      __pycache__/mapper.cpython-38.pyc
  2. 5 5
      config.ini
  3. BIN
      de2/__pycache__/elements.cpython-38.pyc
  4. BIN
      de2/__pycache__/tracer.cpython-38.pyc
  5. 2 2
      de2/elements.py
  6. 3 1
      de2/tracer.py
  7. BIN
      figures/ecological.png
  8. 28 11
      mapper.py

BIN
__pycache__/mapper.cpython-38.pyc


+ 5 - 5
config.ini

@@ -1,6 +1,6 @@
 [simulation]
 ; Whether to visualize the movement of vessels on the map
-visualization = false
+visualization = true
 
 ; Whether to print internal simulation trace to the terminal
 verbose = false
@@ -14,7 +14,7 @@ statistics = true
 ; When zero or negative, runs the simulator as fast as possible
 ; Note: timescale must be strictly positive when using the
 ;    visualization!
-timescale = 0
+timescale = 0.001
 
 ; The time to end the simulation. When zero, no end time
 ;    is considered.
@@ -26,13 +26,13 @@ schedule_file = results-de2/plan.csv
 
 [movement]
 ; When true, the velocities below are ignored and the ETA is used instead
-use_eta = true
+use_eta = false
 
 ; Both tugging and sailing are sampled from a normal distribution
 ;    with the parameters defined below.
 ; Everything is using SI units, so m/s instead of knots!
-velocity_mean_tugging = 3.343889
-velocity_std_tugging = 0.2572222
+velocity_mean_tugging = 4.455
+velocity_std_tugging = 2.001
 velocity_mean_sailing = 3.343889
 velocity_std_sailing = 0.2572222
 velocity_max = 10.28889

BIN
de2/__pycache__/elements.cpython-38.pyc


BIN
de2/__pycache__/tracer.cpython-38.pyc


+ 2 - 2
de2/elements.py

@@ -369,8 +369,8 @@ class Port(CoupledDEVS):
 		self.connectPorts(self.pool.vessel_out, self.sailer.vessel_in)
 		self.connectPorts(self.sailer.vessel_out, self.pool.vessel_in)
 
-		# self.clock = self.addSubModel(Clock("clock"))
-		# self.connectPorts(self.clock.outp, self.sailer.update)
+		self.clock = self.addSubModel(Clock("clock"))
+		self.connectPorts(self.clock.outp, self.sailer.update)
 
 	def select(self, imm_children):
 		for child in imm_children:

+ 3 - 1
de2/tracer.py

@@ -139,6 +139,8 @@ class Streamer:
             elif t.startswith("START: "):
                 self.starting_time = float(t[7:])
             elif len(t) > 0:
-                self.vessels.append(StreamedVessel.from_str(text))
+                sv = StreamedVessel.from_str(t)
+                if not any([v.mmsi == sv.mmsi for v in self.vessels]):
+                    self.vessels.append(sv)
 
     def flush(self): pass

BIN
figures/ecological.png


+ 28 - 11
mapper.py

@@ -16,16 +16,19 @@ class PoABLayer(BaseLayer):
     """
 
     __colors__ = {
-        "highlight": [255, 255, 0, 100], # yellow
+        "highlight": [150, 0, 250, 200], # yellow
         "nodes": [150, 0, 250, 200],     # purple
-        "sailing": [0, 150, 250, 200],   # blue
-        "tugging": [150, 250, 0, 200]    # green
+        "ecological": [0, 255, 0, 200]    # green
     }
 
     def __init__(self, sim=None, streamer=None):
         self.sim = sim
         self.streamer = streamer
         self.sim_active = False
+        self.starting = False
+
+        self.sailing = sim.model.sailer.v_sailing
+        self.tugging = sim.model.sailer.v_tugging
 
         self.berths = pd.read_csv("berths.csv")
         # Uncomment the following lines if the berths list should only look at berths used
@@ -104,7 +107,10 @@ class PoABLayer(BaseLayer):
 
 
         if not self.sim_active:
-            ui_manager.status("Press Space to Start Simulation")
+            if self.starting:
+                ui_manager.status("Starting Simulation...")
+            else:
+                ui_manager.status("Press Space to Start Simulation")
         else:
             # Show the simulation time in top right
             # model = self.sim.model
@@ -118,9 +124,18 @@ class PoABLayer(BaseLayer):
             for vessel in self.streamer.vessels:
                 if vessel.source is not None and vessel.target is not None:
                     if vessel.task == "sailing":
-                        self.painter.set_color(self.__colors__["sailing"])
+                        rng = self.sailing
                     else:
-                        self.painter.set_color(self.__colors__["tugging"])
+                        rng = self.tugging
+                    col = self.__colors__["ecological"]
+                    dist = 0
+                    if vessel.velocity < rng[0]:
+                        dist = rng[0] - vessel.velocity
+                    elif vessel.velocity > rng[1]:
+                        dist = vessel.velocity - rng[1]
+                    col[0] = min(255, int(dist) * 50)
+                    col[1] = 255 - min(255, int(dist) * 50)
+                    self.painter.set_color(col)
 
                     # Obtain (and draw) vessel trajectory
                     if vessel.mmsi not in self.vcache or self.vcache[vessel.mmsi] != vessel.source:
@@ -130,6 +145,8 @@ class PoABLayer(BaseLayer):
 
                     path, dists = self.pcache[vessel.mmsi]
 
+                    self.draw_path(path, proj)
+
                     # Compute distance traveled and draw a vessel there
                     tot_distance = vessel.total_distance
                     traveled_approx = tot_distance - vessel.distance_left
@@ -150,12 +167,11 @@ class PoABLayer(BaseLayer):
                     if euler_distance(sx + dx, sy + dy, mouse_x, mouse_y) < 10:
                         self.painter.set_color(self.__colors__["highlight"])
                         tooltips.append("%s (MMSI: %s)" % (str(vessel.name), str(vessel.mmsi)))
-                        tooltips.append("velocity: %.3f m/s" % vessel.velocity)
-                        tooltips.append("distance total: %.3f m" % vessel.total_distance)
-                        tooltips.append("distance left:  %.3f m" % vessel.distance_left)
-                        tooltips.append("ETA: %s" % epoch_to_str(vessel.distance_left / vessel.velocity + ts))
+                        tooltips.append("task: %s | ETA: %s" % (vessel.task, epoch_to_str(vessel.distance_left / vessel.velocity + ts)))
+                        tooltips.append("velocity: %.3f m/s%s" % (vessel.velocity, "" if dist > 0 else " (ecological)"))
+                        tooltips.append("dist left/total: %.3f/%.3f m" % (vessel.distance_left, vessel.total_distance))
 
-                        self.draw_path(path, proj)
+                        # self.draw_path(path, proj)
                     self.draw_shape(sx + dx, sy + dy)
 
         ui_manager.tooltip("\n".join(tooltips))
@@ -168,6 +184,7 @@ class PoABLayer(BaseLayer):
     def on_key_release(self, key, modifiers):
         if key == pyglet.window.key.SPACE:
             if self.sim is not None:
+                self.starting = True
                 self.sim.simulate()
                 self.sim_active = True