I am including the .run file here. I used the script to generate output on csv files. Now I would like to have excel files as an output for easy data manipulation and analysis. I am not sure how to modify the script to have 1 excel file for each scenario in the sensitivity analysis. I would appreciate the help!
load amplxl.dll;
reset;
model XX.mod;
data XX.dat;
option solver knitro; # CPLEX como solver
option knitro_options 'act_lppenalty=2 presolve=1';
option show_stats 1;
# Testing values_sensitivity analysis (This values are defined in the .mod multiplying the parameters for the sensitivity analysis)
set valores_sens_e := 1..16 by 8;
set valores_sens_q := 0..16 by 8;
set valores_sens_th := 5..20 by 10;
set valores_sens_test := 0.02..0.1 by 0.05;
#Defining the parameters_character strings
param archivo_resumen symbolic default "resumen.txt";
param archivo_instancia symbolic default "instancia.xlsx";
#Defining instances counter
param total_de_instancias default card(valores_sens_e)*card(valores_sens_q)*card(valores_sens_th)*card(valores_sens_test);
param contador_instancia default 1;
printf "Correr %s instancias\n", total_de_instancias; # Number of instances to run
# Esta parte imprime los nombres de las columnas
printf "sens_e\tsens_q\tsens_th\tsens_test" > (archivo_resumen); # cabecera de la tabla resumen: parámetros sensibilizados
#ahora los indicadores
#Officce occupancy
for{j in STAFF}
{
printf "\tOOS_%s",j > (archivo_resumen);
}
for{d in DEPARTMENTS}
{
printf "\tOOD_%s",d > (archivo_resumen);
}
#Home occupancy
for{j in STAFF}
{
printf "\tHOS_%s",j > (archivo_resumen);
}
for{d in DEPARTMENTS}
{
printf "\tHOD_%s",d > (archivo_resumen);
}
#Total_Occupancy_OFFICE
printf "\tOO" > (archivo_resumen);
#Total_Occupancy_HOME
printf "\tHO" > (archivo_resumen);
#Inf
for{j in STAFF}
{
printf "\tIS_%s",j > (archivo_resumen);
}
for{d in DEPARTMENTS}
{
printf "\tID_%s",d > (archivo_resumen);
}
#Total_Inf
printf "\tIT" > (archivo_resumen);
#Q
for{j in STAFF}
{
printf "\tQS_%s",j > (archivo_resumen);
}
for{d in DEPARTMENTS}
{
printf "\tQD_%s",d > (archivo_resumen);
}
#Total_Q
printf "\tQT" > (archivo_resumen);
#Total_Home
printf "\tTH" > (archivo_resumen);
#Total_Office
printf "\tTO" > (archivo_resumen);
#Objective
printf "\tBEN" > (archivo_resumen);
printf "\n" > (archivo_resumen);
# Experiments
----------------------------------------------##Here I am guessing where to include the table definition##---------------------------------------------
table W2Results OUT "amplxl" "W2.xlsx" "Allocation_office":
{j in STAFF} -> [staff], {d in DEPARTMENTS} <X[j,d] ~ ("Department" & d)> ;
write table W2Results;
table W2Results2 OUT "amplxl" "W2.xlsx" "Allocation_home":
{j in STAFF} -> [staff], {d in DEPARTMENTS} <Y[j,d] ~ ("Department" & d)> ;
write table W2Results2;
table W2Results3 OUT "amplxl" "W2.xlsx" "Contacts_D":
{j in STAFF} -> [staff], {d in DEPARTMENTS} <k[j,d] ~ ("Department" & d)> ;
write table W2Results3;
table W2Results4 OUT "amplxl" "W2.xlsx" "Inf, Test":
[TIME], {t in TIME} (sum {j in STAFF, d in DEPARTMENTS} I[t,j,d] ~ Inf, sum {j in STAFF, d in DEPARTMENTS} Q[t,j,d] ~ Test) ;
write table W2Results4;
table W2Results5 OUT "amplxl" "W2.xlsx" "Allocation_office_home_inf":
[], ALL.val ~ Objective, sum {j in STAFF, d in DEPARTMENTS} X[j,d] ~ Total_office, sum {j in STAFF, d in DEPARTMENTS} Y[j,d] ~ Total_home,
1/15*(sum {t in TIME, j in STAFF, d in DEPARTMENTS} I[t,j,d] ) ~ InfA ;
write table W2Results5;
table W2Results6 OUT "amplxl" "W2.xlsx" "Inf_D":
{t in TIME} -> [time], { d in DEPARTMENTS} <sum {j in STAFF} I[t,j,d] ~ ("Department" & d)> ;
write table W2Results6;
table W2Results7 OUT "amplxl" "W2.xlsx" "Inf_S":
{t in TIME} -> [time], { j in STAFF} <sum {d in DEPARTMENTS} I[t,j,d] ~ ("Staff" & j)> ;
write table W2Results7;
table W2Results8 {j in STAFF} OUT "amplxl" "W2.xlsx" ("Istaff" & j) :
[TIME], {d in DEPARTMENTS} < {t in TIME} I[t,j,d] ~ (d)> ;
write table W2Results8;
table W2Results9 {j in STAFF} OUT "amplxl" "W2.xlsx" ("Qstaff" & j) :
[TIME], {d in DEPARTMENTS} < {t in TIME} Q[t,j,d] ~ (d)> ;
write table W2Results9;
----------------------------------------------##Here I am guessing where to include the table definition##---------------------------------------------
#defining the loop for the experiments
for {tar in valores_sens_e, cap in valores_sens_q, wei in valores_sens_th, tei in valores_sens_test}
{
# Mostrar cosas por pantalla
printf "\n\nInstancia %s de %s (%3.1f\%)\n", contador_instancia, total_de_instancias, (contador_instancia/total_de_instancias)*100;
printf "sens_e\t%s\n", tar;
printf "sens_q\t%s\n", cap;
printf "sens_th\t%s\n", wei;
printf "sens_test\t%s\n", tei;
printf "\n";
# Parameters_change
let sens_e := tar;
let sens_q := cap;
let sens_th := wei;
let sens_test := tei;
solve;
# name of the output file #I used this script for csv output file
# escribir archivo de instancia
----------------------------------------------##This block write the solutions to "archivo_instancia" 1 file by experiment##---------------------------------------------
#I would like to write the tables defined above to archivo_instancia
#display ALL.val > (archivo_instancia); # Muestra el valor de la FO
#display X.val > (archivo_instancia);
#display Y.val > (archivo_instancia);
#display k.val > (archivo_instancia);
#display I.val > (archivo_instancia);
#display Q.val > (archivo_instancia);
#display (1/T*(sum {t in TIME, j in STAFF, d in DEPARTMENTS} I[t,j,d] )) > (archivo_instancia);
#display (1/T*(sum {t in TIME, j in STAFF, d in DEPARTMENTS} Q[t,j,d] )) > (archivo_instancia);
#display sum {j in STAFF, d in DEPARTMENTS} X[j,d] > (archivo_instancia);
#display sum {j in STAFF, d in DEPARTMENTS} Y[j,d] > (archivo_instancia);
#display {t in TIME, d in DEPARTMENTS} (sum {j in STAFF} I[t,j,d]) > (archivo_instancia);
#display {t in TIME} (sum {j in STAFF, d in DEPARTMENTS} I[t,j,d]) > (archivo_instancia);
----------------------------------------------##This block write the solutions to "archivo_instancia" 1 file by experiment##---------------------------------------------
# cerrar el archivo de salida
close archivo_instancia;
# Comienzo a escribir la fila de la tabla resumen para esta instancia
printf "%s\t%s\t%s\t%s", sens_e, sens_q, sens_th, sens_test > (archivo_resumen);
#INDICADORES (caso factible)
if solve_result = "solved" then
{
#Officce occupancy
for{j in STAFF}
{
printf "\t%s",((sum {d in DEPARTMENTS} X[j,d]) / (sum {d in DEPARTMENTS} (n[j,d]))) > (archivo_resumen);
}
for{d in DEPARTMENTS}
{
printf "\t%s", (((sum {j in STAFF} X[j,d])) / (sum {j in STAFF} (n[j,d]))) > (archivo_resumen);
}
#Home occupancy
for{j in STAFF}
{
printf "\t%s",((sum {d in DEPARTMENTS} Y[j,d]) / (sum {d in DEPARTMENTS} (n[j,d]))) > (archivo_resumen);
}
for{d in DEPARTMENTS}
{
printf "\t%s", ((sum {j in STAFF} Y[j,d]) / (sum {j in STAFF} (n[j,d]))) > (archivo_resumen);
}
#Total_Occupancy_OFFICE
printf "\t%s", ((sum {j in STAFF, d in DEPARTMENTS} X[j,d]) / (sum {j in STAFF, d in DEPARTMENTS} (n[j,d]))) > (archivo_resumen);
#Total_Occupancy_HOME
printf "\t%s", ((sum {j in STAFF, d in DEPARTMENTS} Y[j,d]) / (sum {j in STAFF, d in DEPARTMENTS} (n[j,d]))) > (archivo_resumen);
#Inf
for{j in STAFF}
{
printf "\t%s", (1/T*(sum {t in TIME, d in DEPARTMENTS} I[t,j,d] )) > (archivo_resumen);
}
for{d in DEPARTMENTS}
{
printf "\t%s", (1/T*(sum {t in TIME, j in STAFF} I[t,j,d] )) > (archivo_resumen);
}
#Total_Inf
printf "\t%s", (1/T*(sum {t in TIME, j in STAFF, d in DEPARTMENTS} I[t,j,d] )) > (archivo_resumen);
#Q
for{j in STAFF}
{
printf "\t%s", (1/15*(sum {t in TIME, d in DEPARTMENTS} Q[t,j,d] )) > (archivo_resumen);
}
for{d in DEPARTMENTS}
{
printf "\t%s", (1/15*(sum {t in TIME, j in STAFF} Q[t,j,d] )) > (archivo_resumen);
}
#Total_Q
printf "\t%s", (1/15*(sum {t in TIME, j in STAFF, d in DEPARTMENTS} Q[t,j,d] )) > (archivo_resumen);
#Total_HOME
printf "\t%s", (sum{j in STAFF, d in DEPARTMENTS} Y[j,d]) > (archivo_resumen);
#Total_OFFICE
printf "\t%s", (sum{j in STAFF, d in DEPARTMENTS} X[j,d]) > (archivo_resumen);
#Objective
printf "\t%s", sum{j in STAFF, d in DEPARTMENTS} X[j,d] > (archivo_resumen);
}
#INDICADORES (caso infactible)
else if solve_result = "infeasible" then
{
#Officce occupancy
for{j in STAFF}
{
printf "\tinfeasible" > (archivo_resumen);
}
for{d in DEPARTMENTS}
{
printf "\tinfeasible" > (archivo_resumen);
}
#Home occupancy
for{j in STAFF}
{
printf "\tinfeasible" > (archivo_resumen);
}
for{d in DEPARTMENTS}
{
printf "\tinfeasible" > (archivo_resumen);
}
#Total_Occupancy_OFFICE
printf "\tinfeasible" > (archivo_resumen);
#Total_Occupancy_HOME
printf "\tinfeasible" > (archivo_resumen);
#Inf
for{j in STAFF}
{
printf "\tinfeasible" > (archivo_resumen);
}
for{d in DEPARTMENTS}
{
printf "\tinfeasible" > (archivo_resumen);
}
#Total_Inf
printf "\tinfeasible" > (archivo_resumen);
#Q
for{j in STAFF}
{
printf "\tinfeasible" > (archivo_resumen);
}
for{d in DEPARTMENTS}
{
printf "\tinfeasible" > (archivo_resumen);
}
#Total_Q
printf "\tinfeasible" > (archivo_resumen);
#Total_Home
printf "\tinfeasible" > (archivo_resumen);
#OTotal_Office
printf "\tinfeasible" > (archivo_resumen);
#Objective
printf "\tinfeasible" > (archivo_resumen);
}
#INDICADORES (caso que no es óptimo ni infactible a.k.a. "problem!")
else
{
#Officce occupancy
for{j in STAFF}
{
printf "\tproblem!" > (archivo_resumen);
}
for{d in DEPARTMENTS}
{
printf "\tproblem!" > (archivo_resumen);
}
#Home occupancy
for{j in STAFF}
{
printf "\tproblem!" > (archivo_resumen);
}
for{d in DEPARTMENTS}
{
printf "\tproblem!" > (archivo_resumen);
}
#Total_Occupancy_OFFICE
printf "\tproblem!" > (archivo_resumen);
#Total_Occupancy_HOME
printf "\tproblem!" > (archivo_resumen);
#Inf
for{j in STAFF}
{
printf "\tproblem!" > (archivo_resumen);
}
for{d in DEPARTMENTS}
{
printf "\tproblem!" > (archivo_resumen);
}
#Total_Inf
printf "\tproblem!" > (archivo_resumen);
#Q
for{j in STAFF}
{
printf "\tproblem!" > (archivo_resumen);
}
for{d in DEPARTMENTS}
{
printf "\tproblem!" > (archivo_resumen);
}
#Total_Q
printf "\tproblem!" > (archivo_resumen);
#Total_Home
printf "\tproblem!" > (archivo_resumen);
#Total_Office
printf "\tproblem!" > (archivo_resumen);
#Objective
printf "\tproblem!" > (archivo_resumen);
}
printf "\n" > (archivo_resumen);
let contador_instancia := contador_instancia + 1;
}
close archivo_resumen;