Initializing help system before first use

Setops - Index sets


Type: Programming
Rating: 2
Description: A example showing the use of index sets and in particular, creating the union and intersection of index sets.
File(s): xbsetops.java


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());
  for(i=0;i=0)  c.addElement(a.getIndexName(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);
  for(i=0; i