Skip to content

Commit

Permalink
Distribute agents from trajectories or generate positions
Browse files Browse the repository at this point in the history
  • Loading branch information
chraibi committed Oct 22, 2024
1 parent 4f0d5b9 commit e58592c
Show file tree
Hide file tree
Showing 3 changed files with 111 additions and 158 deletions.
86 changes: 22 additions & 64 deletions files/inifile.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"simulation_parameters": {
"fps": 100,
"time_step": 0.001,
"number_agents": 82,
"number_agents": 20,
"simulation_time": 200
},
"measurement_line": {
Expand Down Expand Up @@ -87,71 +87,29 @@
}
]
},
"accessible_areas": [
"accessible_areas": [
{
"id": 1,
"vertices": [
[
47.0,
100.0
-3.5,
-1.0
],
[
60.0,
100.0
3.5,
-1.0
],
[
60.0,
104.0
3.5,
19.0
],
[
47.0,
104.0
]
]
},
{
"id": 2,
"vertices": [
[
60.0,
101.7
],
[
62.0,
101.7
],
[
62.0,
102.3
],
[
60.0,
102.3
]
]
},
{
"id": 3,
"vertices": [
[
62.0,
100.0
],
[
65.0,
100.0
],
[
65.0,
104.0
],
[
62.0,
104.0
-3.5,
19.0
]
]
}
],
],
"destinations": [
{
"id": 1,
Expand Down Expand Up @@ -225,24 +183,24 @@
"distribution_polygons": [
{
"id": 1,
"vertices": [
"vertices": [
[
48.0,
100.0
-3.5,
-1.0
],
[
55.0,
100.0
3.5,
-1.0
],
[
55.0,
104.0
3.5,
19.0
],
[
48.0,
104.0
-3.5,
19.0
]
]
]
}
]
]
}
123 changes: 60 additions & 63 deletions positions.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -320,53 +320,53 @@
},
{
"cell_type": "code",
"execution_count": 4,
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# # Parse the WKT polygon\n",
"# geometry2 = from_wkt(\n",
"# \"POLYGON ((-8.88 -7.63, 8.3 -7.63, 8.3 27.95, -8.88 27.95, -8.88 -7.63), (-3.54 -1.13, -3.57 19.57, -1.52 19.57, -1.37 19.71, -0.87 19.71, -0.72 19.57, -0.42 19.57, -0.27 19.71, -0.27 21.09, -0.42 21.23, -0.72 21.23, -0.87 21.09, -1.37 21.09, -1.52 21.23, -1.67 21.23, -1.67 21.18, -1.545 21.18, -1.4200000000000002 21.065, -1.4200000000000002 19.735, -1.545 19.62, -3.6199999999999997 19.62, -3.59 -1.13, -3.54 -1.13), (3.57 -0.89, 3.64 19.64, 1.47 19.57, 1.32 19.71, 0.82 19.71, 0.67 19.57, 0.38 19.57, 0.23 19.71, 0.23 21.09, 0.38 21.23, 0.67 21.23, 0.82 21.09, 1.32 21.09, 1.47 21.23, 1.62 21.23, 1.62 21.18, 1.4949999999999999 21.18, 1.37 21.065, 1.37 19.735, 1.4949999999999999 19.62, 3.69 19.69, 3.6199999999999997 -0.89, 3.57 -0.89))\"\n",
"# )\n",
"# Parse the WKT polygon\n",
"geometry2 = from_wkt(\n",
" \"POLYGON ((-8.88 -7.63, 8.3 -7.63, 8.3 27.95, -8.88 27.95, -8.88 -7.63), (-3.54 -1.13, -3.57 19.57, -1.52 19.57, -1.37 19.71, -0.87 19.71, -0.72 19.57, -0.42 19.57, -0.27 19.71, -0.27 21.09, -0.42 21.23, -0.72 21.23, -0.87 21.09, -1.37 21.09, -1.52 21.23, -1.67 21.23, -1.67 21.18, -1.545 21.18, -1.4200000000000002 21.065, -1.4200000000000002 19.735, -1.545 19.62, -3.6199999999999997 19.62, -3.59 -1.13, -3.54 -1.13), (3.57 -0.89, 3.64 19.64, 1.47 19.57, 1.32 19.71, 0.82 19.71, 0.67 19.57, 0.38 19.57, 0.23 19.71, 0.23 21.09, 0.38 21.23, 0.67 21.23, 0.82 21.09, 1.32 21.09, 1.47 21.23, 1.62 21.23, 1.62 21.18, 1.4949999999999999 21.18, 1.37 21.065, 1.37 19.735, 1.4949999999999999 19.62, 3.69 19.69, 3.6199999999999997 -0.89, 3.57 -0.89))\"\n",
")\n",
"\n",
"\n",
"# # Extract exterior coordinates\n",
"# exterior_x, exterior_y = geometry2.exterior.xy\n",
"# Extract exterior coordinates\n",
"exterior_x, exterior_y = geometry2.exterior.xy\n",
"\n",
"# # Extract interior coordinates (holes)\n",
"# interiors = [list(interior.coords.xy) for interior in geometry2.interiors]\n",
"# exterior_x = list(geometry2.exterior.xy[0])\n",
"# exterior_y = list(geometry2.exterior.xy[1])\n",
"# Extract interior coordinates (holes)\n",
"interiors = [list(interior.coords.xy) for interior in geometry2.interiors]\n",
"exterior_x = list(geometry2.exterior.xy[0])\n",
"exterior_y = list(geometry2.exterior.xy[1])\n",
"\n",
"# # Extract interior coordinates (holes) as lists\n",
"# interiors = [\n",
"# (list(interior.xy[0]), list(interior.xy[1])) for interior in geometry2.interiors\n",
"# ]\n",
"# Extract interior coordinates (holes) as lists\n",
"interiors = [\n",
" (list(interior.xy[0]), list(interior.xy[1])) for interior in geometry2.interiors\n",
"]\n",
"\n",
"# # Create the figure\n",
"# fig = go.Figure()\n",
"# Create the figure\n",
"fig = go.Figure()\n",
"\n",
"# # Plot exterior\n",
"# fig.add_trace(go.Scatter(x=exterior_x, y=exterior_y, mode=\"lines\", name=\"Exterior\"))\n",
"# Plot exterior\n",
"fig.add_trace(go.Scatter(x=exterior_x, y=exterior_y, mode=\"lines\", name=\"Exterior\"))\n",
"\n",
"# # Plot interiors (holes)\n",
"# for i, (x, y) in enumerate(interiors):\n",
"# fig.add_trace(go.Scatter(x=x, y=y, mode=\"lines+markers\", name=f\"Interior {i+1}\"))\n",
"# print(f\"Interior {i+1}. {x = }, {y = }\")\n",
"# Plot interiors (holes)\n",
"for i, (x, y) in enumerate(interiors):\n",
" fig.add_trace(go.Scatter(x=x, y=y, mode=\"lines+markers\", name=f\"Interior {i+1}\"))\n",
" print(f\"Interior {i+1}. {x = }, {y = }\")\n",
"\n",
"\n",
"\n",
"# # fig.add_trace(go.Scatter(x=combined_x, y=combined_y, mode='lines+markers', fill='toself', name='Combined Polygon'))\n",
"# fig.add_trace(go.Scatter(x=combined_x, y=combined_y, mode='lines+markers', fill='toself', name='Combined Polygon'))\n",
"\n",
"# # Update layout\n",
"# fig.update_layout(\n",
"# title=\"Polygon with Interior Holes\",\n",
"# xaxis_title=\"X Coordinate\",\n",
"# yaxis_title=\"Y Coordinate\",\n",
"# showlegend=True,\n",
"# width=600,\n",
"# height=600,\n",
"# )\n"
"# Update layout\n",
"fig.update_layout(\n",
" title=\"Polygon with Interior Holes\",\n",
" xaxis_title=\"X Coordinate\",\n",
" yaxis_title=\"Y Coordinate\",\n",
" showlegend=True,\n",
" width=600,\n",
" height=600,\n",
")\n"
]
},
{
Expand Down Expand Up @@ -438,13 +438,13 @@
"outputs": [],
"source": [
"walkable_area = pedpy.WalkableArea(geometry)\n",
"for filename in filenames:\n",
"for filename in filenames[0:1]:\n",
" df, frame_after_decrease = get_first_frame_pedestrian_passes_line(filename)\n",
" df['ox'] = 0.0\n",
" df['oy'] = 0.1\n",
" delta_frame = 20\n",
" start = frame_after_decrease - delta_frame\n",
" end = frame_after_decrease + 3*delta_frame\n",
" end = frame_after_decrease + 100*delta_frame\n",
" df = df[(df['frame'] >= start) & (df['frame'] <= end)]\n",
" trajectory_data = pedpy.TrajectoryData(df, frame_rate=50)\n",
" anim = animate(trajectory_data, walkable_area, every_nth_frame=1, title_note=f'{extract_title(filename)}, start={frame_after_decrease}')\n",
Expand All @@ -466,41 +466,38 @@
"metadata": {},
"outputs": [],
"source": [
"# filename = filenames[0]\n",
"# df = pd.read_csv(\n",
"# filename, sep=\"\\t\", names=[\"id\", \"frame\", \"x\", \"y\", \"z\", \"m\"], comment=\"#\"\n",
"# )\n",
"filename = filenames[0]\n",
"df = pd.read_csv(\n",
" filename, sep=\"\\t\", names=[\"id\", \"frame\", \"x\", \"y\", \"z\", \"m\"], comment=\"#\"\n",
" )\n",
"\n",
"\n",
"# threshold = 0.1\n",
"# dy= 1\n",
"# ped = 70\n",
"# df_ped = df[(df['frame']>=frame_after_decrease) & (df['id']==ped)]\n",
"# def premovement_frame(df_ped, threshold, dy):\n",
"# premovement_frame = pd.NA\n",
"# while pd.isna(premovement_frame):\n",
"# premovement_frame = df_ped[df_ped['y'].diff(dy).abs() > threshold]['frame'].min()\n",
"# dy += 1\n",
"# return premovement_frame, dy\n",
"threshold = 0.1\n",
"dy= 1\n",
"ped = 70\n",
"df_ped = df[(df['frame']>=frame_after_decrease) & (df['id']==ped)]\n",
"def premovement_frame(df_ped, threshold, dy):\n",
" premovement_frame = pd.NA\n",
" while pd.isna(premovement_frame):\n",
" premovement_frame = df_ped[df_ped['y'].diff(dy).abs() > threshold]['frame'].min()\n",
" dy += 1\n",
" return premovement_frame, dy\n",
"\n",
"\n",
"\n",
"# premovement_frame, dy = premovement_frame(df_ped, threshold, dy)\n",
"premovement_frame, dy = premovement_frame(df_ped, threshold, dy)\n",
"\n",
"# print(f\"{premovement_frame = }, {dy = }\")\n",
"# plt.plot( df_ped['frame'], df_ped['y'],'-k', ms=1, alpha=0.6)\n",
"# plt.plot(premovement_frame, df_ped[df_ped['frame']==premovement_frame]['y'], 'ro', label='Pre-movement frame')\n",
"# plt.ylabel('Y Position')\n",
"# plt.xlabel('Frame')\n",
"# plt.title(f'Pedestrian {ped}. {premovement_frame = }, {dy = }')\n"
"print(f\"{premovement_frame = }, {dy = }\")\n",
"plt.plot( df_ped['frame'], df_ped['y'],'-k', ms=1, alpha=0.6)\n",
"plt.plot(premovement_frame, df_ped[df_ped['frame']==premovement_frame]['y'], 'ro', label='Pre-movement frame')\n",
"y_pos = df_ped[df_ped['frame'] == premovement_frame]['y'].values[0]\n",
"print(y_pos)\n",
"plt.text(premovement_frame, y_pos, f'({premovement_frame}, {y_pos:.2f})', \n",
" verticalalignment='bottom', horizontalalignment='right')\n",
"plt.ylabel('Y Position')\n",
"plt.xlabel('Frame')\n",
"plt.title(f'Pedestrian {ped}. {premovement_frame = }, {dy = }')\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
Expand Down
Loading

0 comments on commit e58592c

Please sign in to comment.