FRAMES NO FRAMES

Class IlcResourceConstraintIterator

Definition file: ilsched/schedule.h
Include file: <ilsched/ilsched.h>

An instance of this class traverses a set of resource constraints (for example, the resource constraints on a given activity or the resource constraints on a given resource, etc.).

Iterating over all the resource constraints on the resources required or provided by an activity is actually an iteration over all the resources that might be required or provided by the activity. If you want to iterate only the resource constraints that are surely required or provided by the activity, then you should use the isTrue member function of the class of constraints involved. The following example shows a program that correctly makes this distinction.

Example

The following program correctly makes the distinction between iterating over all the resources that might be used by an activity versus iterating only those resources that are surely used by the activity.

 Must be during search (e.g., inside a goal)

  IloSolver solver = getSolver();
  IlcScheduler schedule(solver, 0, 50);

  IlcUnaryResource resource1(schedule);
  resource1.setName("resource 1");

  IlcUnaryResource resource2(schedule);
  resource2.setName("resource 2");

  IlcUnaryResource resource3(schedule);
  resource3.setName("resource 3");

  IlcActivity activity(schedule, 5);
  activity.setName("activity");

  solver.add(activity.requires(resource1));
  solver.add(activity.requires(resource3) || activity.requires(resource2));

  for (IlcResourceConstraintIterator ite(activity); ite.ok();
      ++ite)
    solver.out() << activity << " might require "
      << ite.getResource() << endl;
  solver.out() << endl;

  for (IlcResourceConstraintIterator ite2(activity); ite2.ok();
      ++ite2)
    if ((*ite2).isTrue())
      solver.out() << activity << " requires "
         << ite2.getResource() << endl;
  solver.out() << endl;
 

The output of that program looks like this:

   activity[0..45 -- 5 --> 5..50] might require resource 2[1]
   activity[0..45 -- 5 --> 5..50] might require resource 3[1]
   activity[0..45 -- 5 --> 5..50] might require resource 1[1]

   activity[0..45 -- 5 --> 5..50] requires resource 1[1]
  

For more information, see Precedence Graph Constraints.

See Also:

Constructor and Destructor Summary
public IlcResourceConstraintIterator(IlcActivity activity, IlcResourceConstraintIteratorFilter filter=IlcAllConstraints)
public IlcResourceConstraintIterator(IlcActivity activity, IlcTimeExtent extent, IlcResourceConstraintIteratorFilter filter=IlcAllConstraints)
public IlcResourceConstraintIterator(IlcResource resource, IlcResourceConstraintIteratorFilter filter=IlcAllConstraints)
public IlcResourceConstraintIterator(IlcResource resource, IlcTimeExtent extent, IlcResourceConstraintIteratorFilter filter=IlcAllConstraints)
public IlcResourceConstraintIterator(IlcResourceConstraint constraint, IlcResourceConstraintIteratorFilter filter)
Method Summary
public IlcActivitygetActivity() const
public IlcResourcegetResource() const
public IlcBoolok() const
public IlcResourceConstraintoperator*() const
public IlcResourceConstraintIterator &operator++()
Constructor and Destructor Detail

IlcResourceConstraintIterator

public IlcResourceConstraintIterator(IlcActivity activity, IlcResourceConstraintIteratorFilter filter=IlcAllConstraints)

This constructor creates an iterator to traverse all the resources required or provided by activity.


IlcResourceConstraintIterator

public IlcResourceConstraintIterator(IlcActivity activity, IlcTimeExtent extent, IlcResourceConstraintIteratorFilter filter=IlcAllConstraints)

This constructor creates an iterator to traverse all the resources required or provided by activity throughout the time extent indicated by extent.


IlcResourceConstraintIterator

public IlcResourceConstraintIterator(IlcResource resource, IlcResourceConstraintIteratorFilter filter=IlcAllConstraints)

This constructor creates an iterator to traverse all the activities that require or provide resource.


IlcResourceConstraintIterator

public IlcResourceConstraintIterator(IlcResource resource, IlcTimeExtent extent, IlcResourceConstraintIteratorFilter filter=IlcAllConstraints)

This constructor creates an iterator to traverse all the activities that require or provide resource throughout the time extent indicated by extent.


IlcResourceConstraintIterator

public IlcResourceConstraintIterator(IlcResourceConstraint constraint, IlcResourceConstraintIteratorFilter filter)

When a resource precedence graph is associated with the resource required by constraint, this constructor creates an iterator to traverse the subset of resource constraints specified by the filter given as the second argument. If the resource is not associated with a precedence graph, this constructor raises an error.

Before entering the search, only the filter IlcSuccessors is permitted. It allows the definition of an iterator that traverses the subset of resource constraints rct0 for which the successor relation (rct,rct0) has been added via the member function rct.IlcResourceConstraint::setSuccessor(rct0). Any attempt to use another filter before entering the search will raise an error. In search, all the filters are allowed.

For example, the following loop, during the search, displays the set of resource constraints that are direct successors of the resource constraint rct in the precedence graph of the resource:

 for (IlcResourceConstraintIterator ite(rct, IlcDirectSuccessors);
        ite.ok();
        ++ite) {
     solver.out() << *ite << endl;
 }

Method Detail

getActivity

public IlcActivity getActivity() const

This member function returns the activity involved in the resource constraint located at the current position of the invoking iterator.


getResource

public IlcResource getResource() const

This member function returns the resource involved in the resource constraint located at the current position of the invoking iterator.


ok

public IlcBool ok() const

This member function returns IlcTrue if the current position of the iterator is a valid one. It returns IlcFalse if all the constraints have been scanned by the iterator.


operator*

public IlcResourceConstraint operator*() const

This operator accesses the instance of IlcResourceConstraint located at the current position of the iterator. If the iterator is set past the end position, then this operator returns an empty handle.


operator++

public IlcResourceConstraintIterator & operator++()

This left-increment operator shifts the current position of the iterator.