| |||||||||||||
Workshop - Displaying solution information Description A small planning problem. The example composes constraints, LP solves the problem and then prints the variables. Model version 'xbworkrng' shows how to retrieve ranging information for variables and constraints and how to change the number-printing format.
Source Files By clicking on a file name, a preview is opened at the bottom of this page.
xbworkrng.cxx /******************************************************** Xpress-BCL C++ Example Problems =============================== file xbworkrng.cxx `````````````````` Workshop planning example. Test ranges and number printing format. (c) 2008-2024 Fair Isaac Corporation author: S.Heipcke, 2003, rev. Mar. 2011 ********************************************************/ #include <iostream> #include "xprb_cpp.h" using namespace std; using namespace ::dashoptimization; #define NProd 2 /* Number of products */ #define NShop 3 /* Number of workshops */ #define WMAX 40 /* Maximum weekly working time */ /****DATA****/ int DUR[][NShop] = {{5, 9, 7}, /* Duration of product p on shop s */ {10, 2, 5}}; int RES[] = {10, 8}; /* Man hours per unit */ int PRICE[] = {108, 84}; /* Selling price per unit */ /***********************************************************************/ int main(int argc, char **argv) { int p,s; XPRBexpr l; XPRBvar x[NProd]; /* Amount of product p */ XPRBprob pb("Workshop"); /* Initialize a new problem in BCL */ XPRBctr c[NShop]; /****VARIABLES****/ for(p=0;p<NProd;p++) x[p] = pb.newVar("x"); /****OBJECTIVE****/ for(p=0;p<NProd;p++) l += (PRICE[p]-5*RES[p])*x[p]; pb.setObj(pb.newCtr("OBJ",l)); /* Set obj. function: maximize benefit */ /****CONSTRAINTS****/ for(s=0;s<NShop;s++) /* Limit on weekly working hours */ { l = 0; for(p=0;p<NProd;p++) l += DUR[p][s]*x[p]; c[s] = pb.newCtr("ResMax",l <= WMAX); } /****SOLVING + OUTPUT****/ pb.setRealFmt("%4.2e"); for(p=0;p<NProd;p++) { x[p].print(); cout << " "; } cout << endl; pb.setSense(XPRB_MAXIM); pb.lpOptimize(""); /* Solve the LP-problem */ cout << "Objective: " << pb.getObjVal() << endl; /* Get objective value */ pb.setRealFmt("%g, "); for(p=0;p<NProd;p++) /* Print the solution values */ x[p].print(); cout << endl; pb.setRealFmt("%8.4f"); pb.print(); /* Row ranges */ cout << "Ctr: Lower activity, Upper activity, Unit cost DN, Unit cost UP" << endl; for(s=0;s<NShop;s++) { cout << c[s].getName() << ": " << c[s].getRNG(XPRB_LOACT) << ", "; cout << c[s].getRNG(XPRB_UPACT) << ", " << c[s].getRNG(XPRB_UDN); cout << ", " << c[s].getRNG(XPRB_UUP) << endl; } /* Column ranges */ cout << "Var: Lower activity, Upper activity, Unit cost DN, Unit cost UP, Lower profit, Upper profit" << endl; for(p=0;p<NProd;p++) { cout << x[p].getName() << ": " << x[p].getRNG(XPRB_LOACT) << ", "; cout << x[p].getRNG(XPRB_UPACT) << ", " << x[p].getRNG(XPRB_UDN) << ", "; cout << x[p].getRNG(XPRB_UUP) << ", " << x[p].getRNG(XPRB_LCOST) << ", "; cout << x[p].getRNG(XPRB_UCOST) << endl; } return 0; } | |||||||||||||
© Copyright 2024 Fair Isaac Corporation. |