Hi
How do I see the sensitivity analysis ( shadow price and constraint slack ) using the GUROBI and C ++
I found it but did not understand how to use:
"objval: The objective value of the computed solution.
runtime: The elapsed wall-clock time (in seconds) for the optimization.
x: The computed solution. This array contains one entry for each column of A.
slack: The constraint slack for the computed solution. This array contains one entry for each row of A.
qcslack: The quadratic constraint slack in the current solution. This array contains one entry for second-order cone constraint and one entry for each quadratic constraint. The slacks for the second-order cone constraints appear before the slacks for the quadratic constraints.
pi: Dual values for the computed solution (also known as shadow prices). This array contains one entry for each row of A." (Gurobi Optimizer Reference Manual, page 432)
My source code is:
//------------------------------------------------------------------------------
#include "gurobi_c++.h"
using namespace std;
//------------------------------------------------------------------------------
int main()
{
try
{
GRBEnv env = GRBEnv();
GRBModel model = GRBModel(env);
//Criando as variaveis
GRBVar x1 = model.addVar(0, GRB_INFINITY, 0, GRB_CONTINUOUS, "Soja");//GRB_CONTINUOUS, GRB_BINARY, GRB_INTEGER
GRBVar x2 = model.addVar(0, GRB_INFINITY, 0, GRB_CONTINUOUS, "Milho");//GRB_CONTINUOUS, GRB_BINARY, GRB_INTEGER
GRBVar x3 = model.addVar(0, 15000, 0, GRB_CONTINUOUS, "Serragem");//GRB_CONTINUOUS, GRB_BINARY, GRB_INTEGER
//Adicionando novas variaveis
model.update();
//Funcao Objetivo: min= 0.50*x1+0.30*x2+0.02*x3
model.setObjective(0.50*x1+0.30*x2+0.02*x3, GRB_MINIMIZE);
//primeira restricao: 15*x1+12*x2+2*x3>=10000
model.addConstr(15*x1+12*x2+2*x3>=10000, "Calcio");
//segunda restricao: 40*x1+10*x2+1*x3>=20000
model.addConstr(40*x1+10*x2+1*x3>=20000, "Proteina");
//terceira restricao: 290*x1+340*x2+80*x3>=200000000
model.addConstr(290*x1+340*x2+80*x3>=200000000, "Carboidratos");
//Resolvendo o modelo
model.optimize();
cout << x1.get(GRB_StringAttr_VarName) << " = "<< x1.get(GRB_DoubleAttr_X) << endl;
cout << x2.get(GRB_StringAttr_VarName) << " = "<< x2.get(GRB_DoubleAttr_X) << endl;
cout << x3.get(GRB_StringAttr_VarName) << " = "<< x3.get(GRB_DoubleAttr_X) << endl;
cout << "Função Objetivo = " << model.get(GRB_DoubleAttr_ObjVal) << endl;
} catch(GRBException e)
{
cout << "Erro = " << e.getErrorCode() << endl;
cout << e.getMessage() << endl;
} catch(...)
{
cout << "Erro durante a otimizacao" << endl;
}
return 0;
}
//------------------------------------------------------------------------------
Thanks
Jorge Reis