Fzina commited on
Commit
c241619
·
verified ·
1 Parent(s): f82645d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -4
app.py CHANGED
@@ -128,6 +128,18 @@ class TrafficSimEnv(gym.Env):
128
  # Prior to commit had a lot of errors regarding expected output errors
129
  def optimize_signal_rl(congestion_level):
130
  try:
 
 
 
 
 
 
 
 
 
 
 
 
131
  # Create environment
132
  env = DummyVecEnv([lambda: TrafficSimEnv(congestion_level)])
133
 
@@ -145,15 +157,14 @@ def optimize_signal_rl(congestion_level):
145
  action, _ = model.predict(obs, deterministic=True)
146
  obs, reward, done, truncated, info = env.step(action)
147
 
148
- # Ensure single observation extraction
149
  obs = obs[0]
150
  reward = reward[0]
151
  done = done[0]
152
  truncated = truncated[0]
153
- info = info[0]
154
 
155
- # Log each step for debugging
156
- print(f"STEP: action={action}, obs={obs}, reward={reward}, done={done}, truncated={truncated}, info={info}")
157
 
158
  if done or truncated:
159
  break
 
128
  # Prior to commit had a lot of errors regarding expected output errors
129
  def optimize_signal_rl(congestion_level):
130
  try:
131
+
132
+ # Map congestion levels (string to numeric)
133
+ congestion_map = {
134
+ "Low": 2,
135
+ "Medium": 5,
136
+ "High": 8
137
+ }
138
+
139
+ if isinstance(congestion_level, str):
140
+ congestion_level = congestion_map.get(congestion_level, 5) # Default to "Medium" if unrecognized
141
+
142
+
143
  # Create environment
144
  env = DummyVecEnv([lambda: TrafficSimEnv(congestion_level)])
145
 
 
157
  action, _ = model.predict(obs, deterministic=True)
158
  obs, reward, done, truncated, info = env.step(action)
159
 
160
+ # Unpack single observations (adjust for DummyVecEnv behavior)
161
  obs = obs[0]
162
  reward = reward[0]
163
  done = done[0]
164
  truncated = truncated[0]
 
165
 
166
+ # Debugging logs for better tracking
167
+ logging.debug(f"Action: {action}, Observation: {obs}, Reward: {reward}, Done: {done}")
168
 
169
  if done or truncated:
170
  break