IBM ILOG Scheduler User's Manual > Advanced Concepts > More Advanced Problem Modeling with Concert Technology > Defining the Problem, Designing a Model > Workers

There are two important facts to represent with respect to each worker. First, the worker can perform only one activity at a time: each individual worker is a unary resource. Second, the worker must be at the construction site in order to perform an activity. In other words, we need to preclude the worker's performance of any activity when he or she is not present on the site.

In that sense, the worker is already "required" whenever he or she is not on the site. The use of IloTimeExtent in a requires statement makes it possible to represent this constraint.

The code that follows defines a new class, Worker. Each instance of the class Worker includes an instance of IloUnaryResource and an instance of IloActivity. The activity represents the presence of the worker on the site and is said to require the resource before its start and after its end. This guarantees that the worker cannot perform any other activity before arrival at the site nor after departure from the site.

class Worker {
private:
  IloUnaryResource _resource;
  IloActivity      _limitedAttendanceOnSite;
public:
  Worker(IloModel, IloNum durMaxOnSite, const char* name);
  ~Worker();
  IloUnaryResource getResource() const {
    return _resource;
  }
  IloActivity getAttendance() const {
    return _limitedAttendanceOnSite;
  }
  IloNumVar getAttendanceProcessingTime() const {
    return _limitedAttendanceOnSite.getProcessingTimeVariable();
  }
  IloConstraint coverAttendance(IloActivity act);
};
  
Worker::Worker(IloModel model, IloNum durMaxOnSite, const char* name)
  :_resource(model.getEnv()),
   _limitedAttendanceOnSite(model.getEnv(), 
                            IloNumVar(model.getEnv(), 0, durMaxOnSite, IloNumVar::Int))
{
  _resource.setName(name);
  _resource.setCapacityEnforcement(IloMediumHigh);
  _limitedAttendanceOnSite.setName("Attendance");
  _resource.setObject(this);
  /* NEGATIVE STATEMENT: THE FACT THAT THE WORKER IS ON THE SITE FOR
     A LIMITED INTERVAL OF TIME MEANS THAT IT IS TO BE CONSIDERED
     "REQUIRED" BEFORE AND AFTER THIS INTERVAL OF TIME. */
  model.add(_limitedAttendanceOnSite.requires(_resource,
                                              1,
                                              IloBeforeStartAndAfterEnd));
}
 
Worker::~Worker()
{}
 
IloConstraint Worker::coverAttendance(IloActivity act){
  return (act.startsAfterStart(_limitedAttendanceOnSite) &&
          _limitedAttendanceOnSite.endsAfterEnd(act));
}