![]() | |||||||||||||||||
| |||||||||||||||||
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.
xbworks.cs /********************************************************/ /* Xpress-BCL C# Example Problems */ /* ============================== */ /* */ /* file xbworks.cs */ /* ``````````````` */ /* Example for the use of Xpress-BCL */ /* (Workshop planning example from XPRESS-MP tutorial) */ /* */ /* (c) 2008-2023 Fair Isaac Corporation */ /* authors: S.Heipcke, D.Brett. */ /********************************************************/ using System; using System.Text; using System.IO; using BCL; namespace Examples { public class TestWorkshop { const int NProd = 2; /* Number of products */ const int NShop = 3; /* Number of workshops */ const int WMAX = 40; /* Maximum weekly working time */ /****DATA****/ int[,] DUR = {{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 */ /***********************************************************************/ public static void Main() { XPRB.init(); int p,s; XPRBexpr l = new XPRBexpr(); XPRBvar[] x = new XPRBvar[NProd]; /* Amount of product p */ XPRBprob pb = new XPRBprob("Workshop"); /* Initialize a new problem in BCL */ TestWorkshop TestInstance = new TestWorkshop(); /****VARIABLES****/ for(p=0;p<NProd;p++) x[p] = pb.newVar("x"); /****OBJECTIVE****/ for(p=0;p<NProd;p++) l += (TestInstance.PRICE[p] - 5 * TestInstance.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 = new XPRBexpr(); for (p = 0; p < NProd; p++) l += TestInstance.DUR[p,s] * x[p]; pb.newCtr("ResMax",l <= WMAX); } /****SOLVING + OUTPUT****/ pb.setSense(BCLconstant.XPRB_MAXIM); pb.lpOptimize(); System.Console.WriteLine("Objective: " + pb.getObjVal()); /* Get objective value */ for(p=0;p<NProd;p++) /* Print the solution values */ System.Console.Write(x[p].getName() + ":" + x[p].getSol() + " "); System.Console.WriteLine(); return; } } }
| |||||||||||||||||
© Copyright 2023 Fair Isaac Corporation. |