Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion python/simod/demand_sample.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
# You should have received a copy of the GNU Lesser General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
from amodsim.init import config
from simod.init import config
import math
import pandas as pd
import numpy as np
Expand Down
4 changes: 2 additions & 2 deletions python/simod/resources/config.cfg
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@

# common data for all experiments
data_dir: 'C:/AIC Experiment data/VGA/'
data_dir: '/Users/adela/Documents/bakalarka/randomdemand/'
map_dir: $data_dir + 'maps/'

experiments_dir: 'HERE FILL THE PROJECT EXPERIMENT DIR PATH/'
experiments_dir: '/Users/adela/Documents/bakalarka/randomdemand/experiments/test/'
rci_experiments_dir: 'HERE FILL THE PROJECT RCI EXPERIMENT DIR PATH/'

# change this for each experiment!
Expand Down
6 changes: 3 additions & 3 deletions python/simod/station_positions_map.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
# You should have received a copy of the GNU Lesser General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
from amodsim.init import config
from simod.init import config

import numpy as np
import matplotlib
Expand All @@ -26,7 +26,7 @@
import roadmaptools.utm
import matplotlib
import matplotlib.font_manager as fm
import amodsim.demand
import simod.demand

from mpl_toolkits.axes_grid1.anchored_artists import AnchoredSizeBar
from matplotlib.colors import LogNorm
Expand Down Expand Up @@ -69,7 +69,7 @@
# map = np.random.rand(len(lon_range), len(lat_range))

# - fill heatmap
demand_data = amodsim.demand.load(config.trips_path)
demand_data = simod.demand.load(config.trips_path)
xlist, ylist = roadmaptools.plotting.export_nodes_for_matplotlib(demand_data[["from_lat", "from_lon"]].to_numpy())
for i, x in enumerate(xlist):
y = ylist[i]
Expand Down
4 changes: 2 additions & 2 deletions python/simod/statistics/comparisons/comparison_table.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
# You should have received a copy of the GNU Lesser General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
from amodsim.init import config
from simod.init import config

import numpy as np
import roadmaptools.inout
Expand All @@ -25,7 +25,7 @@
from typing import List
# from scripts.printer import print_table
# from statistics.model.traffic_load import VehiclePhase
from amodsim.statistics.traffic_density_histogram import TrafficDensityHistogram
from simod.statistics.traffic_density_histogram import TrafficDensityHistogram


def compute_stats(result: List, histogram: TrafficDensityHistogram, load) -> List:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#

from amodsim.init import config
from simod.init import config

import matplotlib.pyplot as plt
import numpy as np
import statistics.model.traffic_load as traffic_load

from matplotlib.axes import Axes
from amodsim.statistics.traffic_density_histogram import TrafficDensityHistogram, HIGH_THRESHOLD, HISTOGRAM_SAMPLES
from simod.statistics.traffic_density_histogram import TrafficDensityHistogram, HIGH_THRESHOLD, HISTOGRAM_SAMPLES
from statistics.model.traffic_load import VehiclePhase


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,16 @@
# You should have received a copy of the GNU Lesser General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
from amodsim.init import config
from simod.init import config

import numpy as np
import pandas as pd
import matplotlib
import matplotlib.pyplot as plt
import datetime
import roadmaptools.inout
import amodsim.statistics.model.occupancy as occupancy
import amodsim.statistics.comparisons.common as common
import simod.statistics.model.occupancy as occupancy
import simod.statistics.comparisons.common as common

from matplotlib.ticker import FuncFormatter

Expand Down
4 changes: 2 additions & 2 deletions python/simod/statistics/comparisons/performance_comparison.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@
# You should have received a copy of the GNU Lesser General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
from init import config
from simod.init import config

import matplotlib.pyplot as plt
import amodsim.statistics.model.ridesharing as ridesharing
import simod.statistics.model.ridesharing as ridesharing


ih_capacity1_stats = ridesharing.load(config.comparison.experiment_1_dir)
Expand Down
10 changes: 5 additions & 5 deletions python/simod/statistics/comparisons/sensitivity_analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@
# You should have received a copy of the GNU Lesser General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
from amodsim.init import config
from simod.init import config

from typing import List, Tuple
import roadmaptools.inout
import amodsim.statistics.model.edges as edges
import amodsim.statistics.model.transit as transit
import amodsim.statistics.model.ridesharing as ridesharing
import amodsim.statistics.model.service as service
import simod.statistics.model.edges as edges
import simod.statistics.model.transit as transit
import simod.statistics.model.ridesharing as ridesharing
import simod.statistics.model.service as service
import matplotlib.pyplot as plt

delay_experiments = ["sw-vga-max_delay_3_min", "sw-vga", "sw-vga-max_delay_5_min", "sw-vga-max_delay_6_min"]
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
from simod.init import config

import numpy as np
import pandas.errors
import roadmaptools.inout
import simod.statistics.model.traffic_load as traffic_load
import simod.statistics.model.transit as transit
import simod.statistics.model.edges as edges
import simod.statistics.model.ridesharing as ridesharing
import simod.statistics.model.service as service
import simod.statistics.model.occupancy as occupancy

from typing import List, Dict, Iterable
from pandas import DataFrame
from roadmaptools.printer import print_table, print_info
from simod.statistics.traffic_density_histogram import TrafficDensityHistogram
from simod.statistics.model.vehicle_state import VehicleState


def compute_stats(result: Dict, histogram: TrafficDensityHistogram, load, experiment_dir: str,
edge_data: DataFrame) -> List:
# km total
transit_data = transit.load(experiment_dir)
km_total_window = int(round(transit.get_total_distance(transit_data, edge_data, True) / 1000 / 100))
km_per_served_demand = round(km_total_window / (result["demandsCount"] - result["numberOfDemandsDropped"]), 3)

dropped_demand_count = result["numberOfDemandsDropped"]
demand_count_served = result["demandsCount"] - result["numberOfDemandsDropped"]

occupancies = occupancy.load(experiment_dir)
occupancies_in_window = occupancy.filter_window(occupancies)
used_cars_count = len(occupancies_in_window.vehicle_id.unique())

# delay
service_stat = service.load_dataframe(experiment_dir)
delays_window = service.get_delays(service_stat, True, False)
mean_delay = int(round(delays_window.mean() / 1000))

transfers_count = result['transfersDone']

return [km_total_window, dropped_demand_count, used_cars_count, mean_delay, demand_count_served,
km_per_served_demand, transfers_count]

exp_dir_1 = '/Users/adela/Documents/bakalarka/vysledky2/InsertionHeuristic/Archiv/experiments/test/'
# exp_dir_2 = '/Users/adela/Documents/bakalarka/vysledky2/transferInsertionHeuristic/Archiv/experiments/test/'
exp_dir_2 = '/Users/adela/Documents/bakalarka/randomdemand/experiments/test/'

exp_dir_3 = '/Users/adela/Documents/bakalarka/vysledky2/taset/Archiv/experiments/test/'

edges_path = '/Users/adela/Documents/bakalarka/randomdemand/maps/edges.geojson'
loaded_edges = roadmaptools.inout.load_geojson(edges_path)
edge_data = edges.make_data_frame(loaded_edges)
edge_object_data = edges.load_edges_mapped_by_id(loaded_edges)

results_insertion_heuristic \
= roadmaptools.inout.load_json(exp_dir_1 + config.statistics.result_file_name)
results_insertion_heuristic_transfer \
= roadmaptools.inout.load_json(exp_dir_2 + config.statistics.result_file_name)
results_taset \
= roadmaptools.inout.load_json(exp_dir_3 + config.statistics.result_file_name)

loads_insertion_heuristic = traffic_load.load_all_edges_load_history(
exp_dir_1 + config.statistics.all_edges_load_history_file_name)
loads_insertion_heuristic_transfer = traffic_load.load_all_edges_load_history(
exp_dir_2 + config.statistics.all_edges_load_history_file_name)
loads_taset = traffic_load.load_all_edges_load_history(
exp_dir_3 + config.statistics.all_edges_load_history_file_name)

histogram = TrafficDensityHistogram(edge_object_data)

insertion_heuristic_data = compute_stats(results_insertion_heuristic, histogram, loads_insertion_heuristic["ALL"],
exp_dir_1, edge_data)
insertion_heuristic_transfer_data = compute_stats(results_insertion_heuristic_transfer, histogram,
loads_insertion_heuristic_transfer["ALL"], exp_dir_2,
edge_data)
taset_data = compute_stats(results_taset, histogram, loads_taset["ALL"],
exp_dir_3, edge_data)

output_table = np.array([[" ", "INSERTION HEURISTIC", "INSERTION HEURISTIC TRANSFER", "GREEDY HEURISTIC TRANSFER"],
["Dropped demands", insertion_heuristic_data[1], insertion_heuristic_transfer_data[1],
taset_data[1]],
["Demands served", insertion_heuristic_data[4], insertion_heuristic_transfer_data[4],
taset_data[4]],
["Total transfers", insertion_heuristic_data[6], insertion_heuristic_transfer_data[6],
taset_data[6]],
["Total veh. dist. traveled (km)", insertion_heuristic_data[0],
insertion_heuristic_transfer_data[0], taset_data[0]],
["Total veh. dist. traveled per demand served (km)", insertion_heuristic_data[5],
insertion_heuristic_transfer_data[5], taset_data[5]],
["Used car count", insertion_heuristic_data[2], insertion_heuristic_transfer_data[2],
taset_data[2]],
["Average delay (s)", insertion_heuristic_data[3], insertion_heuristic_transfer_data[3],
taset_data[3]],

])

# console results
print("COMPARISON:")
print()
print_table(output_table)
65 changes: 65 additions & 0 deletions python/simod/statistics/delay_percentage.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import pandas.errors
import roadmaptools.inout
import simod.statistics.model.traffic_load as traffic_load
import simod.statistics.model.transit as transit
import simod.statistics.model.edges as edges
import simod.statistics.model.ridesharing as ridesharing
import simod.statistics.model.service as service
import simod.statistics.model.occupancy as occupancy


exp_dir_1 = '/Users/adela/Documents/bakalarka/vysledky2/InsertionHeuristic/Archiv/experiments/test/'
exp_dir_2 = '/Users/adela/Documents/bakalarka/vysledky2/transferInsertionHeuristic/Archiv/experiments/test/'
exp_dir_3 = '/Users/adela/Documents/bakalarka/vysledky2/taset/Archiv/experiments/test/'

save_dir_1 = '/Users/adela/Documents/bakalarka/vysledky2/InsertionHeuristic/Archiv/img/'
save_dir_2 = '/Users/adela/Documents/bakalarka/vysledky2/transferInsertionHeuristic/Archiv/img/'
save_dir_3 = '/Users/adela/Documents/bakalarka/vysledky2/taset/Archiv/img/'


# delays dataframe
# TODO change dir
service_stat = service.load_dataframe(exp_dir_3)
# TODO change dir
save_results_to = save_dir_3

delays = service.get_delays(service_stat, True, False).to_frame()
service_stat['percentage_delay'] = (service_stat['dropoff_time'] - service_stat['demand_time']) / service_stat['min_possible_delay'] - 1
maximum = service_stat['percentage_delay'].max()
service_stat['percentage_delay_norm'] = service_stat['percentage_delay'] / maximum

new_df = service_stat.where(service_stat['percentage_delay'] > 0.0)
new_df = new_df.dropna()

bins = [0.0, 0.1, 0.2, 0.3, 0.4, 0.6, 0.8, 1 * maximum]


bins_df = pd.cut(new_df['percentage_delay'], bins)
print(bins_df.value_counts())

t = bins_df.value_counts(sort=False)
labels = ['< 10 %', '< 20 %', '< 30 %', '< 40 %', '< 60 %', '< 80 %', '81 % +']


counts = t
plt.axis('equal')
explode = bins
colors = ['#191970','#0038E2','#0071C6','#329A82', '#46C3A6', '#93DCCB', '#E0F5F0']
colors2 = ['#E6F7FF', '#BAE7FF', '#91D5FF', '#69C0FF', '#1890FF', '#096DD9', '#0050B3', '#002766']
cc = list(reversed(colors))
counts.plot(kind='pie', fontsize=15, colors=cc, labels=t,
wedgeprops={"edgecolor": "black",
'linewidth': 0.2,
'antialiased': True}
)
plt.legend(labels=labels, loc="best")
plt.ylabel('')


plt.savefig(save_results_to + 'delay_percentages', bbox_inches='tight', transparent=True)


plt.show()
3 changes: 2 additions & 1 deletion python/simod/statistics/demand_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#

from simod.init import config, roadmaptools_config
from simod.init import config
from roadmaptools.config import roadmaptools_config

from tqdm import tqdm
import numpy as np
Expand Down
4 changes: 2 additions & 2 deletions python/simod/statistics/demand_trip_duration_histogram.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@
# You should have received a copy of the GNU Lesser General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
from amodsim.init import config
from simod.init import config

import numpy as np
import matplotlib.pyplot as plt
from matplotlib.ticker import FuncFormatter
from amodsim.statistics.model import demand_trips
from simod.statistics.model import demand_trips

trips_data = demand_trips.load()

Expand Down
Loading