// $Id$ #include "flopc.hpp" using namespace flopc; #include "OsiClpSolverInterface.hpp" #include "OsiSolverInterface.hpp" /* FLOPC++ implementation of a financial planning and control model from "StAMPL: A filtration-oriented modeling tool for stochastic programming" by Fourer and Lopes */ const double inf = 9.9e+32; const double r1 = 1.25; const double r2 = 1.14; const double R1 = 1.06; const double R2 = 1.12; class MP_tree { public: MP_tree() {} virtual int nStages() {return 0;} virtual int nScenarios(int stage) {return 0;} virtual int getindex(int rs, int cs, int q) {return 0;} virtual double probability(int stage, int q) {return 1;} }; class MP_binarytree : public MP_tree { public: MP_binarytree(int depth) : D(depth) {} virtual int nStages() { return D+1; } virtual int nScenarios(int stage) { return int(pow(2,stage)); } virtual int getindex(int rs, int cs, int q) { return q / int(pow(2,(rs-cs))); } virtual double probability(int stage, int q) { return 1.0 / double(nScenarios(stage)); } int D; }; class MP_problem { public: int m; int n; int nz; int *Cst; int *Clg; int *Rnr; double *Elm; double *bl; double *bu; double *c; double *l; double *u; }; struct Cof { Cof(int r, int c, double v) : row(r), col(c), val(v) { cout< coeficients; int k = 0; int ke = 0; for (int j=0; j0) { DE.Elm = new double[DE.nz]; DE.Rnr = new int[DE.nz]; } DE.Cst = new int[DE.n+1]; DE.Clg = new int[DE.n]; for (int j=0; jloadProblem(DE.n, DE.m, DE.Cst, DE.Rnr, DE.Elm, DE.l, DE.u, DE.c, DE.bl, DE.bu); Solver->writeMps("stampl_mat","mps",-1.0); Solver->setObjSense(-1); Solver->initialSolve(); } void determininistic() { int m = 4; int n = 8; int nz = 14; int Cst[] = {0,2,4,6,8,10,12,13,14}; int Rnr[] = {0,1,0,1,1,2,1,2,2,3,2,3,3,3}; double Elm[] = {1, r1, 1, r2, -1, r1, -1, r2, -1, r1, -1, r2, -1, 1}; double bl[] = {55,0,0,80}; double bu[] = {55,0,0,80}; double c[] = {0,0,0,0,0,0,1,-4}; double l[] = {0,0,0,0,0,0,0,0}; double u[] = {inf,inf,inf,inf,inf,inf,inf,inf}; OsiSolverInterface* Solver = new OsiClpSolverInterface; Solver->loadProblem(n, m, Cst, Rnr, Elm, l, u, c, bl, bu); Solver->setObjSense(-1); Solver->initialSolve(); if (Solver->isProvenOptimal() == true) { cout<<"FlopCpp: Optimal obj. value = "<getObjValue()<getNumCols()<<" "<getNumElements()<