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

Setops - Index sets

Description
A example showing the use of index sets and in particular, creating the union and intersection of index sets.

Source Files

xbsetops.java

```/********************************************************
Xpress-BCL Java Example Problems
================================

file xbsetops.java
``````````````````
Set operations.

(c) 2008 Fair Isaac Corporation
author: S.Heipcke, Jan. 2000
********************************************************/

import com.dashoptimization.*;

public class xbsetops
{

/* Define arrays with index names: note that the restriction
to 8 characters does not apply for BCL                    */
static final String city_names[] = {"rome", "bristol", "london", "paris",
"liverpool"};
static final String port_names[] = {"plymouth", "bristol", "glasgow",
"london", "calais", "liverpool"};

/***********************************************************************/

/**** Create the union of two index sets ****/
static XPRBindexSet createUnion(XPRBprob p, XPRBindexSet a, XPRBindexSet b,
String name)
{
int i;
XPRBindexSet c;

c=p.newIndexSet(name,a.getSize()+b.getSize());
return c;
}

/**** Create the intersection of two index sets ****/
static XPRBindexSet createInter(XPRBprob p, XPRBindexSet a, XPRBindexSet b,
String name)
{
int i;
XPRBindexSet c;

c=p.newIndexSet(name,a.getSize()<b.getSize()?a.getSize():b.getSize());
for(i=0;i<a.getSize();i++)
return c;
}

/***********************************************************************/

public static void main(String[] args)
{
XPRB bcl;
XPRBindexSet ports,cities,both,places;
int i;
XPRBprob p;

bcl = new XPRB();                 /* Initialize BCL */
p = bcl.newProb("Setops");        /* Create a new problem */

/* Create sets "cities" and "ports" and add the indices */
cities=p.newIndexSet("cities", city_names.length);