Skip to content

Commit

Permalink
Improve plot labels
Browse files Browse the repository at this point in the history
  • Loading branch information
GoncaloPascoal committed Jul 3, 2022
1 parent ee4316b commit a99a056
Showing 1 changed file with 83 additions and 32 deletions.
115 changes: 83 additions & 32 deletions scripts/pretty_graphs.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,71 +5,122 @@
sns.set(font_scale=1.5) # Adjust this if necessary

CVRP_FILES = [
("data/cvrp-benchmarks/greedy_analysis.csv", "Greedy"),
("data/cvrp-benchmarks/gts_analysis.csv", "Tabu Search"),
("data/cvrp-benchmarks/sa_analysis.csv", "Simulated Annealing"),
("data/cvrp-benchmarks/aco_analysis.csv", "Ant Colony Optimization"),
("data/cvrp-benchmarks/clarke_wright_analysis.csv", "Clarke Wright Savings"),
("data/cvrp-benchmarks/cp_analysis.csv", "Constraint Programming"),
("data/cvrp-benchmarks/sa_clarke_wright.csv", "Simulated Annealing (Clarke Wright)"),
("data/cvrp-benchmarks/sa_greedy.csv", "Simulated Annealing (greedy)"),
("data/cvrp-benchmarks/sa_trivial.csv", "Simulated Annealing (trivial)"),
('data/cvrp-benchmarks/greedy_analysis.csv', 'Greedy'),
('data/cvrp-benchmarks/gts_analysis.csv', 'Tabu Search'),
('data/cvrp-benchmarks/sa_analysis.csv', 'Simulated Annealing'),
('data/cvrp-benchmarks/aco_analysis.csv', 'Ant Colony Optimization'),
('data/cvrp-benchmarks/clarke_wright_analysis.csv', 'Clarke Wright Savings'),
('data/cvrp-benchmarks/sa_clarke_wright.csv', 'Simulated Annealing (Clarke Wright)'),
('data/cvrp-benchmarks/sa_greedy.csv', 'Simulated Annealing (greedy)'),
('data/cvrp-benchmarks/sa_trivial.csv', 'Simulated Annealing (trivial)'),
]

def get_data() -> pd.DataFrame:
dataframes = []

for path, approach in CVRP_FILES:
dt = pd.read_csv(path)
dt["method"] = approach
dt['method'] = approach

dataframes.append(
dt
)

return pd.concat(dataframes, ignore_index=True)

if __name__ == "__main__":
if __name__ == '__main__':
data = get_data()

data['time_us'] /= 1000
data['solution_length'] /= 1000
data = data.rename(columns={'name': 'instance'})

data_full = data.copy()

sa_specific = {
'Simulated Annealing (Clarke Wright)',
'Simulated Annealing (greedy)',
'Simulated Annealing (trivial)'
}

data = data[~data['method'].isin(sa_specific)]
data['bar_plot_labels'] = data.apply(lambda row: f'{row.instance} ({row.num_deliveries})', axis=1)

if not exists('data/pretty_graphs'):
makedirs('data/pretty_graphs')

figsize = (22, 11)
i = 1
plt.figure(figsize=figsize)
sns.lineplot(data=data
[data['method'] != 'Simulated Annealing (Clarke Wright)']
[data['method'] != 'Simulated Annealing (greedy)']
[data['method'] != 'Simulated Annealing (trivial)'],
x="num_deliveries", y="time_us", hue="method", lw=4).set(title="Time performance (μs) (lower is better)")
plt.savefig(f"data/pretty_graphs/graph{i}.png")
ax = sns.lineplot(data=data, x='num_deliveries', y='time_us', hue='method', lw=4)
ax.set(
title='Total Processing Time (lower is better)',
xlabel='Number of Delivery Locations',
ylabel='Processing Time (ms)'
)
ax.legend(title='Method')
plt.savefig(f'data/pretty_graphs/graph{i}.png', bbox_inches='tight')

i += 1
plt.figure(figsize=figsize)
sns.barplot(data=data, x="num_deliveries", y="solution_length", hue="method").set(title="Solution quality (lower is better)")
plt.savefig(f"data/pretty_graphs/graph{i}.png")
ax = sns.lineplot(data=data, x='num_deliveries', y='time_us', hue='method', lw=4)
ax.set(
title='Total Processing Time (lower is better)',
xlabel='Number of Delivery Locations',
ylabel='Processing Time (ms, log scale)',
yscale='log'
)
ax.legend(title='Method')
plt.savefig(f'data/pretty_graphs/graph{i}.png', bbox_inches='tight')

i += 1
plt.figure(figsize=figsize)
sns.barplot(data=data, x="num_deliveries", y="num_vehicles", hue="method").set(title="Number of trucks (lower is better)")
plt.savefig(f"data/pretty_graphs/graph{i}.png")
ax = sns.barplot(data=data, x='bar_plot_labels', y='solution_length', hue='method')
ax.set(
title='Total Solution Length (lower is better)',
xlabel='CVRP Instance (Number of Deliveries)',
ylabel='Solution Length (km)'
)
ax.legend(title='Method')
plt.savefig(f'data/pretty_graphs/graph{i}.png', bbox_inches='tight')

i += 1
plt.figure(figsize=figsize)
sns.barplot(data=data, x="num_deliveries", y="average_load", hue="method").set(title="Average load (higher is better)")
plt.legend(loc='lower right')
plt.savefig(f"data/pretty_graphs/graph{i}.png")
ax = sns.barplot(data=data, x='bar_plot_labels', y='num_vehicles', hue='method')
ax.set(
title='Number of Vehicles Used (lower is better)',
xlabel='CVRP Instance (Number of Deliveries)',
ylabel='Vehicles Used'
)
ax.legend(title='Method')
plt.savefig(f'data/pretty_graphs/graph{i}.png', bbox_inches='tight')

i += 1
plt.figure(figsize=figsize)
ax = sns.barplot(data=data, x='bar_plot_labels', y='average_load', hue='method')
ax.set(
title='Average Vehicle Load (higher is better)',
xlabel='CVRP Instance (Number of Deliveries)',
ylabel='Average Vehicle Load'
)
ax.legend(title='Method', loc='lower right')
plt.savefig(f'data/pretty_graphs/graph{i}.png', bbox_inches='tight')

instances = list(data[data["method"] == "Constraint Programming"]["name"])
instances = list(data[data['method'] == 'Greedy']['instance'])

for instance in instances:
i += 1
instance_data = data[data["name"] == instance]
instance_data = data[data['instance'] == instance]
plt.figure(figsize=figsize)
sns.scatterplot(data=instance_data, x="time_us", y="solution_length", hue="method", s=300).\
set(title=f"Time vs. solution length (instance {instance})", ylim=(0, None), xscale="log")

plt.legend(loc='lower right')
plt.savefig(f"data/pretty_graphs/graph{i}.png")

ax = sns.scatterplot(data=instance_data, x='time_us', y='solution_length', hue='method', s=200)
ax.set(
title=f'Processing Time vs. Solution Length ({instance})',
xlabel='Processing Time (ms, log scale)',
ylabel='Solution Length (km)',
ylim=(0, None),
xscale='log'
)
ax.legend(title='Method', loc='lower right')

plt.savefig(f'data/pretty_graphs/graph{i}.png', bbox_inches='tight')

0 comments on commit a99a056

Please sign in to comment.