FICO Xpress Optimization Examples Repository
 FICO Optimization Community FICO Xpress Optimization Home

Chess - Composing constraints and solving

Description
A tiny LP problem concerning the manufacture of chess boards. The example composes constraints term by term and then solves the problem.

Source Files
By clicking on a file name, a preview is opened at the bottom of this page.

xbchess.cs

/********************************************************/
/*  Xpress-BCL C# Example Problems                      */
/*  ==============================                      */
/*                                                      */
/*  file xbchess.cs                                     */
/*                                       */
/*  Example for the use of Xpress-BCL                   */
/*  (Small LP-problem from XPRESS-MP User Guide)        */
/*                                                      */
/*  (c) 2008-2024 Fair Isaac Corporation                */
/*      authors: S.Heipcke, D.Brett.                    */
/********************************************************/

using System;
using System.Text;
using System.IO;
using BCL;

namespace Examples
{
public class TestChess
{

public static void Main()
{
System.Console.WriteLine("Started Chess Test.\n");
XPRB.init();

//OK, now try a few things from the sample files translated to C#:
XPRBvar xs;               /* Number of small chess sets to make */
XPRBvar xl;               /* Number of large chess sets to make */
XPRBprob p = new XPRBprob("Chess");      /* Initialize a new problem in BCL */

/****VARIABLES****/
xs = p.newVar("xs");
xl = p.newVar("xl");

/****OBJECTIVE****/
p.setObj(p.newCtr("OBJ", 5.0 * xs + 20.0 * xl));

/****CONSTRAINTS****/
/* Define the constraint 3*xs + 2*xl <= 400 */
p.newCtr("mc_time", 3.0 * xs + 2.0 * xl <= 400.0);

/* Define the constraint xs + 3*xl <= 200 */
p.newCtr("wood", xs + (3.0 * xl) <= 200.0);

System.Console.WriteLine("Constraints set\n");

/****SOLVING****/
p.setSense(BCLconstant.XPRB_MAXIM);
p.lpOptimize();              /* Solve the LP-problem */

return;
}
}
}

`