Initializing help system before first use

Setops - Index sets


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


xbsetops.cs
/********************************************************
  Xpress-BCL C# Example Problems
  ==============================

  file xbsetops.cs
  ````````````````
  Set operations.

  (c) 2008 Fair Isaac Corporation
      authors: S.Heipcke, D.Brett.
********************************************************/

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


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

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

        /**** Create the union of two index sets ****/     
        public void createUnion(XPRBprob p, XPRBindexSet a, XPRBindexSet b, 
        out XPRBindexSet c, string name)
        {
            int i, dummy;

            c=p.newIndexSet(name,a.getSize()+b.getSize());
            for(i=0;i<a.getSize();i++)  dummy = c + a.getIndexName(i);
            for(i=0;i<b.getSize();i++)  dummy = c + b.getIndexName(i);
        }

        /**** Create the intersection of two index sets ****/
        public void createInter(XPRBprob p, XPRBindexSet a, XPRBindexSet b, 
        out XPRBindexSet c, string name)
        {
            int i, dummy;

            c=p.newIndexSet(name,a.getSize()<b.getSize()?a.getSize():b.getSize());
            for(i=0;i<a.getSize();i++)
                if (b.getIndex(a.getIndexName(i)) >= 0) dummy = c + a.getIndexName(i);
        }

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

        public static void Main()
        {
            XPRB.init();
            XPRBindexSet ports,cities,both,places;
            int i, dummy;
            XPRBprob p = new XPRBprob("Setops");              /* Initialize BCL */
            TestSetOps TestInstance = new TestSetOps();

            /* Create sets "cities" and "ports" and add the indices */
            cities=p.newIndexSet("cities",5);
            for (i = 0; i < 5; i++) dummy = cities + TestInstance.city_names[i];
            ports=p.newIndexSet("ports",6);
            for (i = 0; i < 6; i++) dummy = ports + TestInstance.port_names[i];

            /* Create the union of "cities" and "ports" and print it */
            TestInstance.createUnion(p, cities, ports, out places, "places");
            places.print();
            /* Create the intersection of "cities" and "ports", print it */
            TestInstance.createInter(p, cities, ports, out both, "both sets");
            both.print();

            return;
        }
    }
}

© 2001-2020 Fair Isaac Corporation. All rights reserved. This documentation is the property of Fair Isaac Corporation (“FICO”). Receipt or possession of this documentation does not convey rights to disclose, reproduce, make derivative works, use, or allow others to use it except solely for internal evaluation purposes to determine whether to purchase a license to the software described in this documentation, or as otherwise set forth in a written software license agreement between you and FICO (or a FICO affiliate). Use of this documentation and the software described in it must conform strictly to the foregoing permitted uses, and no other use is permitted.