Commit 047cc46d authored by Francois Hamonic's avatar Francois Hamonic
Browse files

contraction benefits ok

parent 2a0e8e7f
...@@ -19,7 +19,7 @@ double eval(T && ls) { ...@@ -19,7 +19,7 @@ double eval(T && ls) {
} }
int main() { 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 << std::fixed << std::setprecision(6);
data_log << "budget,budget_percent,base_ECA,max_delta_ECA,pl_eca_2_ECA,pl_" 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_" "eca_2_obj,pl_eca_2_variables,pl_2_constraints,pl_2_entries,pl_"
......
...@@ -82,7 +82,7 @@ Instance make_instance(const double dist_coef, const double restoration_coef) { ...@@ -82,7 +82,7 @@ Instance make_instance(const double dist_coef, const double restoration_coef) {
} }
int main() { 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 << std::fixed << std::setprecision(6);
data_log << "budget,budget_percent,base_ECA,max_delta_ECA,pl_eca_2_ECA,pl_" 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_" "eca_2_obj,pl_eca_2_variables,pl_2_constraints,pl_2_entries,pl_"
......
...@@ -28,7 +28,7 @@ void parse_quebec(MutableLandscape & landscape, double pow, double median) { ...@@ -28,7 +28,7 @@ void parse_quebec(MutableLandscape & landscape, double pow, double median) {
std::vector<MutableLandscape::Node> node_correspondance; 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"); patches.read_header(io::ignore_extra_column, "area", "xcoord", "ycoord");
double area, xcoord, ycoord; double area, xcoord, ycoord;
while(patches.read_row(area, xcoord, ycoord)) { while(patches.read_row(area, xcoord, ycoord)) {
...@@ -37,7 +37,7 @@ void parse_quebec(MutableLandscape & landscape, double pow, double median) { ...@@ -37,7 +37,7 @@ void parse_quebec(MutableLandscape & landscape, double pow, double median) {
node_correspondance.push_back(u); 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"); links.read_header(io::ignore_extra_column, "from", "to", "Dist");
int from, to; int from, to;
double Dist; double Dist;
...@@ -88,26 +88,16 @@ MutableLandscape * make_landscape(const MutableLandscape & landscape, ...@@ -88,26 +88,16 @@ MutableLandscape * make_landscape(const MutableLandscape & landscape,
} }
int main() { 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 << std::fixed << std::setprecision(6);
data_log << "center " data_log << "center,percent_arcs,nb_vars,nb_constraints,nb_elems,nb_vars_"
<< "percent_arcs " "contract,nb_constraints_contract,nb_elems_contract"
<< "nb_vars " << std::endl;
<< "nb_constraints "
<< "nb_elems "
<< "nb_vars_contract "
<< "nb_constraints_contract "
<< "nb_elems_contract " << std::endl;
MutableLandscape landscape; MutableLandscape landscape;
parse_quebec(landscape, 1, 2300); parse_quebec(landscape, 1, 2300);
const MutableLandscape::Graph & graph = landscape.getNetwork(); const MutableLandscape::Graph & graph = landscape.getNetwork();
// StdMutableLandscapeParser::get().write(*landscape, "output",
// "out_landscape");
MyContractionAlgorithm alg2;
RandomChooser<MutableLandscape::Node> node_chooser; RandomChooser<MutableLandscape::Node> node_chooser;
for(MutableLandscape::NodeIt u(graph); u != lemon::INVALID; ++u) for(MutableLandscape::NodeIt u(graph); u != lemon::INVALID; ++u)
node_chooser.add(u, 1); node_chooser.add(u, 1);
...@@ -116,9 +106,9 @@ int main() { ...@@ -116,9 +106,9 @@ int main() {
const int n_to_test[] = {500}; const int n_to_test[] = {500};
Solvers::PL_ECA_2 * pl_eca_2 = new Solvers::PL_ECA_2(); 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(); 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++) { for(int i = 0; i < nb_tests; i++) {
MutableLandscape::Node center = node_chooser.pick(); MutableLandscape::Node center = node_chooser.pick();
...@@ -134,20 +124,21 @@ int main() { ...@@ -134,20 +124,21 @@ int main() {
std::cout << "nodes : 500" << std::endl std::cout << "nodes : 500" << std::endl
<< "arcs : " << m << 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) for(MutableLandscape::ArcIt a(sub_graph); a != lemon::INVALID; ++a)
arc_chooser.add(a, 1); arc_chooser.add(a, 1);
RestorationPlan<MutableLandscape> plan(*sub_landscape); RestorationPlan<MutableLandscape> plan(*sub_landscape);
for(int percent_arcs = 0; percent_arcs <= 100; percent_arcs += 5) { for(int percent_arcs = 0; percent_arcs <= 100; percent_arcs += 5) {
plan.initElementIDs();
Solution solution2 = pl_eca_2->solve(*sub_landscape, plan, 0); Solution solution2 = pl_eca_2->solve(*sub_landscape, plan, 0);
Solution solution3 = pl_eca_3->solve(*sub_landscape, plan, 0); Solution solution3 = pl_eca_3->solve(*sub_landscape, plan, 0);
data_log << graph.id(center) << " " << percent_arcs << " " data_log << graph.id(center) << "," << percent_arcs << ","
<< solution2.nb_vars << " " << solution2.nb_constraints << solution2.nb_vars << "," << solution2.nb_constraints
<< " " << solution2.nb_elems << " " << "," << solution2.nb_elems << ","
<< solution3.nb_vars << " " << solution3.nb_constraints << solution3.nb_vars << "," << solution3.nb_constraints
<< " " << solution3.nb_elems << std::endl; << "," << solution3.nb_elems << std::endl;
if(percent_arcs == 100) break; if(percent_arcs == 100) break;
for(int i = 0; i < (m / 20); ++i) { for(int i = 0; i < (m / 20); ++i) {
......
...@@ -19,7 +19,7 @@ double eval(T && ls) { ...@@ -19,7 +19,7 @@ double eval(T && ls) {
} }
int main() { 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 << std::fixed << std::setprecision(6);
data_log << "budget,budget_percent,base_ECA,max_delta_ECA,pl_eca_2_ECA,pl_" 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_" "eca_2_obj,pl_eca_2_variables,pl_2_constraints,pl_2_entries,pl_"
......
...@@ -19,7 +19,7 @@ double eval(T && ls) { ...@@ -19,7 +19,7 @@ double eval(T && ls) {
} }
int main() { 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 << std::fixed << std::setprecision(6);
data_log << "budget,budget_percent,base_ECA,max_delta_ECA,pl_eca_2_ECA,pl_" 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_" "eca_2_obj,pl_eca_2_variables,pl_2_constraints,pl_2_entries,pl_"
......
...@@ -23,7 +23,7 @@ double eval(T && ls) { ...@@ -23,7 +23,7 @@ double eval(T && ls) {
} }
int main() { 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 << std::fixed << std::setprecision(6);
data_log data_log
<< "median,restored_prob,budget,budget_percent,base_ECA,max_delta_" << "median,restored_prob,budget,budget_percent,base_ECA,max_delta_"
......
...@@ -84,7 +84,7 @@ Instance make_instance(const double dist_coef, const double restoration_coef) { ...@@ -84,7 +84,7 @@ Instance make_instance(const double dist_coef, const double restoration_coef) {
} }
int main() { 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 << std::fixed << std::setprecision(6);
data_log data_log
<< "dist_coef,restoration_coef,budget,budget_percent,base_ECA,max_" << "dist_coef,restoration_coef,budget,budget_percent,base_ECA,max_"
......
...@@ -23,7 +23,7 @@ double eval(T && ls) { ...@@ -23,7 +23,7 @@ double eval(T && ls) {
} }
int main() { 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 << std::fixed << std::setprecision(6);
data_log << "median,budget,budget_percent,base_ECA,max_delta_ECA,bogo_avg_" 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_" "delta_ECA,naive_inc_delta_ECA,naive_dec_delta_ECA,glutton_inc_"
......
...@@ -23,7 +23,7 @@ double eval(T && ls) { ...@@ -23,7 +23,7 @@ double eval(T && ls) {
} }
int main() { 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 << std::fixed << std::setprecision(6);
data_log data_log
<< "median,budget,budget_percent,base_ECA,max_delta_" << "median,budget,budget_percent,base_ECA,max_delta_"
......
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
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
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
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}")
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
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment