IBM ILOG Solver User's Manual > Extending the Library > Advanced Modeling with Set Variables: Configuring Tankers > Model > Declaring the variables

To represent the orders the imaginary company receives from customers, you first define the class OrderI, identifying each order uniquely and indicating its products, like this:

class OrderI {
private:
  IloInt       _id;
  IloInt       _quantity;
  IloAnySetVar _products;
public:
  OrderI(IloInt id) : _id(id), _quantity(0) {}

  IloInt       getId()       const { return _id;  }
  IloInt       getQuantity() const { return _quantity; }
  void         setQuantity(IloInt quantity) { _quantity = quantity; }
  IloAnySetVar getProducts() const { return _products; }

  void makeProductVar(IloEnv env, IloAnyArray prods);

  void printName(ostream& out) const;
};

You group orders (instances of OrderI) into a global array (Orders) to represent all the orders to fulfill.

To represent the products demanded within an order, you define the class ProductI, indicating which order, which type of product, and which quantity, like this:

class ProductI {
protected:
  Order    _order;
  IloInt   _type;
  IloInt   _quantity;
public:
  ProductI(Order order, IloInt type, IloInt quantity)
    :_order(order) ,_type(type), _quantity(quantity) {}

  Order    getOrder() const    { return _order; }
  IloInt   getType() const     { return _type; }
  IloInt   getQuantity() const { return _quantity; }

  void printName(ostream& out) const;
};

The five different types of products are represented by the integers {1, 2, 3, 4, 5}. You say that 3 and 4 are the two types that cannot be transported in the same truck.

You also represent the trucks by a class--TruckI--with a unique identifier for each truck, an indicator of whether or not that truck is used, a set variable to show which orders are filled by that truck, and another set variable to indicate which tanks make up the truck. You define that class like this:

class TruckI {
private:
  IloInt              _id;
  IloBoolVar           _used;
  IloAnySetVar        _orders;
  IloArray<Tank>      _tanks;
  IloAnySetVar        _tankVar;
public:
  TruckI(IloModel model, IloInt id);

  IloInt               getId() const        { return _id; }
  IloBoolVar            getUsed() const      { return _used; }
  IloAnySetVar         getOrders() const    { return _orders; }
  IloInt               getNbTanks() const   { return 5; }
  IloArray<Tank>       getTanks() const     { return _tanks; }
  IloAnySetVar         getTankVar() const   { return _tankVar; }

  void display(IloSolver solver) const;
};

To represent the tanks that make up a truck, you first enumerate the capacity of the different types of tanks: {1000, 2000, 3000, 4000, 5000}. Then you define the class TankI, like this:

class TankI {
protected:
  IloInt       _id;
  IloIntVar    _type;
  IloIntVar    _load;
  IloInt       _capaMax;
  IloAnySetVar _prodOrders;
public:
  TankI(IloModel model, IloInt id, IloInt capaMax);

  IloInt       getId() const            { return _id; }
  IloIntVar    getType() const          { return _type; }
  IloIntVar    getLoad() const          { return _load; }
  IloInt       getCapacityMax() const   { return _capaMax; }
  IloAnySetVar getProductOrders() const { return _prodOrders; }

  void display  (IloSolver solver) const;
  void printName(ostream& out) const {
    out << "Tank#" << _id;
  }
};

Using these classes, you can express many of the constraints in the problem through their constructors, but before you add the constraints, you must look more closely at how to access attributes of those classes when their objects serve in the model as elements in the domain of a set.