diff --git a/exec/execution_times/aude.cpp b/exec/execution_times/aude.cpp index 0e40c09d93204762f3996c04aeb534cb2fd7aa9f..3fe050e8a851f029b7e829568b19b78f024b4ede 100755 --- a/exec/execution_times/aude.cpp +++ b/exec/execution_times/aude.cpp @@ -19,7 +19,7 @@ double eval(T && ls) { } int main() { - std::ofstream data_log("output/aude_analysis.csv"); + std::ofstream data_log("output/time_aude.csv"); data_log << std::fixed << std::setprecision(6); data_log << "budget,budget_percent,base_ECA,max_delta_ECA,pl_eca_2_ECA,pl_" "eca_2_obj,pl_eca_2_variables,pl_2_constraints,pl_2_entries,pl_" diff --git a/exec/execution_times/biorevaix.cpp b/exec/execution_times/biorevaix.cpp index e141409074b5565b3e9c75d494648c8f683f6f8f..b1d8742b08f60c6451d7ee5d3f9d64452d88f491 100755 --- a/exec/execution_times/biorevaix.cpp +++ b/exec/execution_times/biorevaix.cpp @@ -82,7 +82,7 @@ Instance make_instance(const double dist_coef, const double restoration_coef) { } int main() { - std::ofstream data_log("output/biorevaix_analysis.csv"); + std::ofstream data_log("output/time_biorevaix.csv"); data_log << std::fixed << std::setprecision(6); data_log << "budget,budget_percent,base_ECA,max_delta_ECA,pl_eca_2_ECA,pl_" "eca_2_obj,pl_eca_2_variables,pl_2_constraints,pl_2_entries,pl_" diff --git a/exec/execution_times/contraction_benefits.cpp b/exec/execution_times/contraction_benefits.cpp index 5a15961eabb08b7c0acd8ab955f4f786412cf9e8..6e66eade43648e89bebfbcf1a98573bcb6948198 100755 --- a/exec/execution_times/contraction_benefits.cpp +++ b/exec/execution_times/contraction_benefits.cpp @@ -28,7 +28,7 @@ void parse_quebec(MutableLandscape & landscape, double pow, double median) { std::vector<MutableLandscape::Node> node_correspondance; - io::CSVReader<3> patches("data/quebec_leam_v3/raw/sommets_leam_v3.csv"); + io::CSVReader<3> patches("datas/Montreal_hare/sommets_leam_v3.csv"); patches.read_header(io::ignore_extra_column, "area", "xcoord", "ycoord"); double area, xcoord, ycoord; while(patches.read_row(area, xcoord, ycoord)) { @@ -37,7 +37,7 @@ void parse_quebec(MutableLandscape & landscape, double pow, double median) { node_correspondance.push_back(u); } - io::CSVReader<3> links("data/quebec_leam_v3/raw/aretes_leam_v3.csv"); + io::CSVReader<3> links("datas/Montreal_hare/aretes_leam_v3.csv"); links.read_header(io::ignore_extra_column, "from", "to", "Dist"); int from, to; double Dist; @@ -88,26 +88,16 @@ MutableLandscape * make_landscape(const MutableLandscape & landscape, } int main() { - std::ofstream data_log("output/data.log"); + std::ofstream data_log("output/contraction_benefits.csv"); data_log << std::fixed << std::setprecision(6); - data_log << "center " - << "percent_arcs " - << "nb_vars " - << "nb_constraints " - << "nb_elems " - << "nb_vars_contract " - << "nb_constraints_contract " - << "nb_elems_contract " << std::endl; + data_log << "center,percent_arcs,nb_vars,nb_constraints,nb_elems,nb_vars_" + "contract,nb_constraints_contract,nb_elems_contract" + << std::endl; MutableLandscape landscape; parse_quebec(landscape, 1, 2300); const MutableLandscape::Graph & graph = landscape.getNetwork(); - // StdMutableLandscapeParser::get().write(*landscape, "output", - // "out_landscape"); - - MyContractionAlgorithm alg2; - RandomChooser<MutableLandscape::Node> node_chooser; for(MutableLandscape::NodeIt u(graph); u != lemon::INVALID; ++u) node_chooser.add(u, 1); @@ -116,9 +106,9 @@ int main() { const int n_to_test[] = {500}; Solvers::PL_ECA_2 * pl_eca_2 = new Solvers::PL_ECA_2(); - (*pl_eca_2).setLogLevel(0); + (*pl_eca_2).setLogLevel(0).setTimeout(0); Solvers::PL_ECA_3 * pl_eca_3 = new Solvers::PL_ECA_3(); - (*pl_eca_3).setLogLevel(0).setTimeout(3600); + (*pl_eca_3).setLogLevel(0).setTimeout(0); for(int i = 0; i < nb_tests; i++) { MutableLandscape::Node center = node_chooser.pick(); @@ -134,20 +124,21 @@ int main() { std::cout << "nodes : 500" << std::endl << "arcs : " << m << std::endl; - RandomChooser<MutableLandscape::Arc> arc_chooser; + RandomChooser<MutableLandscape::Arc> arc_chooser(i); for(MutableLandscape::ArcIt a(sub_graph); a != lemon::INVALID; ++a) arc_chooser.add(a, 1); RestorationPlan<MutableLandscape> plan(*sub_landscape); for(int percent_arcs = 0; percent_arcs <= 100; percent_arcs += 5) { + plan.initElementIDs(); Solution solution2 = pl_eca_2->solve(*sub_landscape, plan, 0); Solution solution3 = pl_eca_3->solve(*sub_landscape, plan, 0); - data_log << graph.id(center) << " " << percent_arcs << " " - << solution2.nb_vars << " " << solution2.nb_constraints - << " " << solution2.nb_elems << " " - << solution3.nb_vars << " " << solution3.nb_constraints - << " " << solution3.nb_elems << std::endl; + data_log << graph.id(center) << "," << percent_arcs << "," + << solution2.nb_vars << "," << solution2.nb_constraints + << "," << solution2.nb_elems << "," + << solution3.nb_vars << "," << solution3.nb_constraints + << "," << solution3.nb_elems << std::endl; if(percent_arcs == 100) break; for(int i = 0; i < (m / 20); ++i) { diff --git a/exec/execution_times/marseille.cpp b/exec/execution_times/marseille.cpp index 9988541bacaf81acb370188c230e13a88e38c014..43f504b7fa7ece2f690c806ff8dfef79ba753310 100755 --- a/exec/execution_times/marseille.cpp +++ b/exec/execution_times/marseille.cpp @@ -19,7 +19,7 @@ double eval(T && ls) { } int main() { - std::ofstream data_log("output/marseille_analysis.csv"); + std::ofstream data_log("output/time_marseille.csv"); data_log << std::fixed << std::setprecision(6); data_log << "budget,budget_percent,base_ECA,max_delta_ECA,pl_eca_2_ECA,pl_" "eca_2_obj,pl_eca_2_variables,pl_2_constraints,pl_2_entries,pl_" diff --git a/exec/execution_times/quebec.cpp b/exec/execution_times/quebec.cpp index 768980fe3bc934357edbd645caacfa562fc525af..6e88288e6b6033e167c9421ab7ba585acadd7667 100755 --- a/exec/execution_times/quebec.cpp +++ b/exec/execution_times/quebec.cpp @@ -19,7 +19,7 @@ double eval(T && ls) { } int main() { - std::ofstream data_log("output/quebec_analysis.csv"); + std::ofstream data_log("output/time_quebec.csv"); data_log << std::fixed << std::setprecision(6); data_log << "budget,budget_percent,base_ECA,max_delta_ECA,pl_eca_2_ECA,pl_" "eca_2_obj,pl_eca_2_variables,pl_2_constraints,pl_2_entries,pl_" diff --git a/exec/quality_of_solutions/aude.cpp b/exec/quality_of_solutions/aude.cpp index e8cafd26b710d4cdb8d4105b54ee7359bdc4a4d4..2b7f6bcf48c31e0d2c5c7bfe2776104bb23a0cbf 100755 --- a/exec/quality_of_solutions/aude.cpp +++ b/exec/quality_of_solutions/aude.cpp @@ -23,7 +23,7 @@ double eval(T && ls) { } int main() { - std::ofstream data_log("output/aude_analysis.csv"); + std::ofstream data_log("output/qos_aude.csv"); data_log << std::fixed << std::setprecision(6); data_log << "median,restored_prob,budget,budget_percent,base_ECA,max_delta_" diff --git a/exec/quality_of_solutions/biorevaix.cpp b/exec/quality_of_solutions/biorevaix.cpp index ee02e9465faaf2fd972411c25d6f3be24969dd35..26ca60f2c087d52ebce09c955a1cf016d75c4294 100755 --- a/exec/quality_of_solutions/biorevaix.cpp +++ b/exec/quality_of_solutions/biorevaix.cpp @@ -84,7 +84,7 @@ Instance make_instance(const double dist_coef, const double restoration_coef) { } int main() { - std::ofstream data_log("output/biorevaix_analysis.csv"); + std::ofstream data_log("output/qos_biorevaix.csv"); data_log << std::fixed << std::setprecision(6); data_log << "dist_coef,restoration_coef,budget,budget_percent,base_ECA,max_" diff --git a/exec/quality_of_solutions/marseille.cpp b/exec/quality_of_solutions/marseille.cpp index 23efe3828c25404fe249ebd2f85d21d3fda936f2..a40492112b43a596a710f2b2106ea38790c3ca6b 100755 --- a/exec/quality_of_solutions/marseille.cpp +++ b/exec/quality_of_solutions/marseille.cpp @@ -23,7 +23,7 @@ double eval(T && ls) { } int main() { - std::ofstream data_log("output/marseille_analysis.csv"); + std::ofstream data_log("output/qos_marseille.csv"); data_log << std::fixed << std::setprecision(6); data_log << "median,budget,budget_percent,base_ECA,max_delta_ECA,bogo_avg_" "delta_ECA,naive_inc_delta_ECA,naive_dec_delta_ECA,glutton_inc_" diff --git a/exec/quality_of_solutions/quebec.cpp b/exec/quality_of_solutions/quebec.cpp index e0b5096959db9aff4a0ca997fa09be5b0d12a8ab..51d31c3df432001fb74f38a85116e6882b5b548a 100755 --- a/exec/quality_of_solutions/quebec.cpp +++ b/exec/quality_of_solutions/quebec.cpp @@ -23,7 +23,7 @@ double eval(T && ls) { } int main() { - std::ofstream data_log("output/quebec_analysis.csv"); + std::ofstream data_log("output/qos_quebec.csv"); data_log << std::fixed << std::setprecision(6); data_log << "median,budget,budget_percent,base_ECA,max_delta_" diff --git a/plot_scripts/contraction_benefits.py b/plot_scripts/contraction_benefits.py new file mode 100755 index 0000000000000000000000000000000000000000..789e09d86ad4bc77e7e510365e20ce89943cfffd --- /dev/null +++ b/plot_scripts/contraction_benefits.py @@ -0,0 +1,67 @@ +import matplotlib.pyplot as plt +import csv +import numpy as np +import statistics + +def readCSV(file_name, delimiter=' '): + file = csv.DictReader(open(file_name), delimiter=delimiter) + return list([row for row in file]) + +rows = readCSV('output/contraction_benefits.csv', ",") + + +def substract(a, b): + return [x-y for x,y in zip(a,b)] +def divide(a, b): + return [x/y if y > 0 else 1 for x,y in zip(a,b)] + + +x_datas = np.array(range(0,105,5)) + +def get_datas(name, linstyle, maker_size, t): + return ((name, (linstyle,maker_size)), (x_datas, + np.array([statistics.mean([100*(1-float(row["nb_{}_contract".format(t)])/float(row["nb_{}".format(t)])) for row in rows if int(row["percent_arcs"]) == percent]) for percent in x_datas]) )) + +datas = [ + get_datas("constraints", "s-",8, "constraints"), + get_datas("variables", "o-",8, "vars"), + get_datas("non-zero entries", "P-",8, "elems") +] + + +fig_size = plt.rcParams["figure.figsize"] +fig_size[0] = 10 +fig_size[1] = 5 +plt.rcParams["figure.figsize"] = fig_size + +plt.subplots_adjust(left=0.125, right=0.95, top=0.92, bottom=0.13) + +plt.rcParams.update({'font.size': 16}) + +xmin = min(x_datas) +xmax = max(x_datas) + +plt.xlim(xmin , xmax) + +ymin = 0 +ymax = 100 +yrange = ymax - ymin + +y_border_percent = 7.5 +y_bottom = ymin - y_border_percent * yrange / 100 +y_top = ymax + y_border_percent * yrange / 100 + +plt.ylim(y_bottom, y_top) + + +# plt.title("quebec-{}-{}-ECA value vs available budget.pdf".format(orig, median)) +plt.ylabel('percentage of elements\nremoved by the preprocessing', rotation=90, fontweight ='bold') +plt.xlabel("percentage of restored arcs", fontweight ='bold') + +for ((label,(linestyle,marker_size)),(xdatas,ydatas)) in datas: + plt.plot(xdatas, ydatas, linestyle, markersize=marker_size, label=label) + +legend = plt.legend(loc='upper right', shadow=True, fontsize='medium') + + +plt.savefig("output/contraction_benefits.pdf", dpi=500) \ No newline at end of file diff --git a/plot_scripts/execution_times_tiled.py b/plot_scripts/execution_times_tiled.py new file mode 100644 index 0000000000000000000000000000000000000000..319c180b98f8de8f06a06967291a2012e55ca098 --- /dev/null +++ b/plot_scripts/execution_times_tiled.py @@ -0,0 +1,48 @@ +import matplotlib.pyplot as plt +import csv +import numpy as np + +def readCSV(file_name, delimiter=','): + file = csv.DictReader(open(file_name), delimiter=delimiter) + return list([row for row in file]) + + +def plot(name, subplot, file_name): + subplot.set_title(name) + + rows = readCSV('output/{}'.format(file_name)) + + def get_datas(column_name): + return ([float(row['budget_percent']) for row in rows], [float(row[column_name]) / 1000 for row in rows]) + + datas = [ + (("mip", "v-"), get_datas('pl_2_time')), + (("mip preprocessed", "^-"), get_datas('pl_3_time')) + ] + + for ((label,linestyle),(xdatas,ydatas)) in datas: + subplot.plot(xdatas, ydatas, linestyle, label=label, markersize=3.25) + + subplot.set_yscale('log') + + +fig, axs = plt.subplots(2, 2) +plot("Aude", axs[0, 0], "time_aude.csv") +plot("Montreal", axs[0, 1], "time_quebec_analysis.csv") +plot("Aix", axs[1, 0], "time_biorevaix_analysis.csv") +plot("Marseille", axs[1, 1], "time_marseille_analysis.csv") + +axs[0, 0].set(xlabel=None, ylabel='execution time (s)') +axs[0, 1].set(xlabel=None, ylabel=None) +axs[1, 0].set(xlabel='budget percent', ylabel='execution time (s)') +axs[1, 1].set(xlabel='budget percent', ylabel=None) + +fig.subplots_adjust(bottom=0.2, top=0.91, wspace=0.2, hspace=0.35) +axs.flatten()[-2].legend(loc='upper center', bbox_to_anchor=(1.05, -0.35), ncol=3) + +fig.set_size_inches(8,5) +plt.rcParams.update({'font.size': 18}) + +# plt.tight_layout() +plt.savefig("figures/execution_times.pdf", dpi=500) +plt.show() \ No newline at end of file diff --git a/plot_scripts/optimum_ratios_tiled.py b/plot_scripts/optimum_ratios_tiled.py new file mode 100644 index 0000000000000000000000000000000000000000..20aac40aef56bff6c75930748ce9ba9f95332107 --- /dev/null +++ b/plot_scripts/optimum_ratios_tiled.py @@ -0,0 +1,54 @@ +import matplotlib.pyplot as plt +import csv +import numpy as np + +def readCSV(file_name, delimiter=','): + file = csv.DictReader(open(file_name), delimiter=delimiter) + return list([row for row in file]) + + +def plot(name, subplot, file_name): + rows = readCSV('output/{}'.format(file_name)) + + max_delta = [float(row['max_delta_ECA']) for row in rows] + + def get_datas(solver_name): + return ([float(row['budget_percent']) for row in rows], [float(row[solver_name]) / float(row['opt_delta_ECA']) for row in rows]) + # return ([float(row['budget_percent']) for row in rows], [(float(row[solver_name]) - float(row['bogo_avg_delta_ECA'])) / (float(row['opt_delta_ECA']) - float(row['bogo_avg_delta_ECA'])) for row in rows]) + + datas = [ + (("static decremental", "v--"), get_datas('naive_dec_delta_ECA')), + (("static incremental", "^--"), get_datas('naive_inc_delta_ECA')), + (("decremental greedy", "v-"), get_datas('glutton_dec_delta_ECA')), + (("incremental greedy", "^-"), get_datas('glutton_inc_delta_ECA')), + (("optimal", "s-"), get_datas('opt_delta_ECA')) + ] + + subplot.set_title(name) + + for ((label,linestyle),(xdatas,ydatas)) in datas: + subplot.plot(xdatas, ydatas, linestyle, label=label, markersize=3.25) + + + + +fig, axs = plt.subplots(2, 2) +plot("Aude", axs[0, 0], "qos_aude.csv") +plot("Montreal", axs[0, 1], "qos_quebec.csv") +plot("BiorevAix", axs[1, 0], "qos_biorevaix.csv") +plot("Marseille", axs[1, 1], "qos_marseille.csv") + +axs[0, 0].set(xlabel=None, ylabel='optimum ratio') +axs[0, 1].set(xlabel=None, ylabel=None) +axs[1, 0].set(xlabel='budget percent', ylabel='optimum ratio') +axs[1, 1].set(xlabel='budget percent', ylabel=None) + +fig.subplots_adjust(bottom=0.3, wspace=0.2, hspace=0.35) +axs.flatten()[-2].legend(loc='upper center', bbox_to_anchor=(1.05, -0.35), ncol=3) + +fig.set_size_inches(8,6) +plt.rcParams.update({'font.size': 18}) + +# plt.tight_layout() +plt.savefig("figures/optimum_ratios.pdf", dpi=500) +# plt.show() \ No newline at end of file diff --git a/plot_scripts/pl_sizes_table.py b/plot_scripts/pl_sizes_table.py new file mode 100644 index 0000000000000000000000000000000000000000..abcab2636c294e69057f13fb95060b7c88b8cbe9 --- /dev/null +++ b/plot_scripts/pl_sizes_table.py @@ -0,0 +1,59 @@ +import matplotlib.pyplot as plt +import csv +import numpy as np + + +def readCSV(file_name, delimiter=','): + file = csv.DictReader(open(file_name), delimiter=delimiter) + return list([row for row in file]) + + +def get_datas(rows, column_name): + return [float(row[column_name]) for row in rows] + + +def avg(arr): + if arr[0] != arr[0]: + return "--" + sum = 0 + cpt = 0 + for v in arr: + if v == v: + sum += v + cpt = cpt + 1 + return int(sum / cpt / 10) / 100 + # return int(sum(arr) / len(arr) / 10) / 100 + + +print("\\begin{tabular}{crrrrrrr}") + +print("\t\\multirow{2}{*}{case} & \\multicolumn{3}{c}{MIP} & \\multicolumn{4}{c}{preprocessed MIP}\\tabularnewline") + +print("\t\\cmidrule(lr){2-4}\\cmidrule(lr){5-8}") + +print("\t& \\#var & \\#const & time & \\#var & \\#const & p. time & time \\tabularnewline") + +print("\t\\hline") + + +aude_rows = readCSV('output/time_aude.csv') +print("\tAude & {} & {} & {} & {} & {} & {} & {}\\tabularnewline".format(int(get_datas(aude_rows, "pl_2_variables")[0]), int(get_datas(aude_rows, "pl_2_constraints")[0]), avg(get_datas(aude_rows, "pl_2_time")), int( + get_datas(aude_rows, "pl_3_variables")[0]), int(get_datas(aude_rows, "pl_3_constraints")[0]), avg(get_datas(aude_rows, "pl_3_preprocessing_time")), avg(get_datas(aude_rows, "pl_3_time")))) + + +quebec_rows = readCSV('output/time_quebec.csv') +print("\tMontereal & {} & {} & {} & {} & {} & {} & {}\\tabularnewline".format(int(get_datas(quebec_rows, "pl_2_variables")[0]), int(get_datas(quebec_rows, "pl_2_constraints")[0]), avg(get_datas(quebec_rows, "pl_2_time")), int( + get_datas(quebec_rows, "pl_3_variables")[0]), int(get_datas(quebec_rows, "pl_3_constraints")[0]), avg(get_datas(quebec_rows, "pl_3_preprocessing_time")), avg(get_datas(quebec_rows, "pl_3_time")))) + + +biorevaix_rows = readCSV('output/time_biorevaix.csv') +print("\tAix & {} & {} & {} & {} & {} & {} & {}\\tabularnewline".format(int(get_datas(biorevaix_rows, "pl_2_variables")[0]), int(get_datas(biorevaix_rows, "pl_2_constraints")[0]), avg(get_datas(biorevaix_rows, "pl_2_time")), int( + get_datas(biorevaix_rows, "pl_3_variables")[0]), int(get_datas(biorevaix_rows, "pl_3_constraints")[0]), avg(get_datas(biorevaix_rows, "pl_3_preprocessing_time")), avg(get_datas(biorevaix_rows, "pl_3_time")))) + + +marseille_rows = readCSV('output/time_marseille.csv') +print("\tMarseille & {} & {} & {} & {} & {} & {} & {}\\tabularnewline".format(int(get_datas(marseille_rows, "pl_2_variables")[0]), int(get_datas(marseille_rows, "pl_2_constraints")[0]), avg(get_datas(marseille_rows, "pl_2_time")), int( + get_datas(marseille_rows, "pl_3_variables")[0]), int(get_datas(marseille_rows, "pl_3_constraints")[0]), avg(get_datas(marseille_rows, "pl_3_preprocessing_time")), avg(get_datas(marseille_rows, "pl_3_time")))) + + +print("\\end{tabular}") diff --git a/plot_scripts/table_optimum_ratios.py b/plot_scripts/table_optimum_ratios.py new file mode 100644 index 0000000000000000000000000000000000000000..2a682fa5205f3b281bf65080f5f5397db7b3bd74 --- /dev/null +++ b/plot_scripts/table_optimum_ratios.py @@ -0,0 +1,28 @@ +import matplotlib.pyplot as plt +import csv +import numpy as np +import statistics as stats + +def readCSV(file_name, delimiter=','): + file = csv.DictReader(open(file_name), delimiter=delimiter) + return list([row for row in file]) + + +def plot(name, file_name): + rows = readCSV('output/{}'.format(file_name)) + + def get_datas(solver_name): + return [100 * float(row[solver_name]) / float(row['opt_delta_ECA']) for row in rows] + + IL = get_datas('naive_inc_delta_ECA') + DL = get_datas('naive_dec_delta_ECA') + IG = get_datas('glutton_inc_delta_ECA') + DG = get_datas('glutton_dec_delta_ECA') + + print("{} & {:.3g}~\\% & {:.3g}~\\% & {:.3g}~\\% & {:.3g}~\\% & {:.3g}~\\% & {:.3g}~\\% & {:.3g}~\\% & {:.3g}~\\%\\tabularnewline\n\\hline".format(name, min(IL), stats.mean(IL), min(DL), stats.mean(DL), min(IG), stats.mean(IG), min(DG), stats.mean(DG))) + + +plot("Aude", "qos_aude.csv") +plot("Montreal", "qos_quebec.csv") +plot("Aix", "qos_biorevaix.csv") +plot("Marseille", "qos_marseille.csv") \ No newline at end of file