Class KResource

  • Direct Known Subclasses:
    KDiscreteResource, KUnaryResource

    public class KResource
    extends java.lang.Object
    Resources (machines, raw material etc) can be of two different types :
    - Disjunctive when the resource can process only one task at a time (represented by the class KUnaryResource).
    - Cumulative when the resource can process several tasks at the same time (represented by the class KDiscreteResource).

    Traditional examples of disjunctive resources are Jobshop problems,
    cumulative resources are heavily used for the Resource-Constrained Project
    Scheduling Problem (RCPSP). Note that a disjunctive resource is semantically
    equivalent to a cumulative resource with maximal capacity one and unit
    resource usage for each task using this resource but this equivalence does
    not hold in terms of constraint propagation.

    The following schema shows an example with three tasks A,B and C executing on a disjunctive resource and on a cumulative resource with resource usage 3 for task A, 1 for task B and 1 for task C :



    Tasks may require, provide, consume and produce resources :
    - A task requires a resource if some amount of the resource capacity must be made available for the execution of the activity. The capacity is renewable which means that the required capacity is available after the end of the task.
    - A task provides a resource if some amount of the resource capacity is made available through the execution of the task. The capacity is renewable which means that the provided capacity is available only during the execution of the task.
    - A task consumes a resource if some amount of the resource capacity must be made available for the execution of the task and the capacity is non-renewable which means that the consumed capacity if no longer available at the end of the task.
    - A task produces a resource if some amount of the resource capacity is made available through the execution of the task and the capacity is non-renewable which means that the produced capacity is definitively available after the starting of the task.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      protected boolean swigCMemOwn  
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void addIdleTimeSteps​(KIntArray idleTimeSteps)
      Add idle time steps to this resource.

      During "idle time steps", the resource does nothing, i.e.
      void addTask​(KTask task)  
      void close()
      Close this resource
      void delete()  
      protected void finalize()  
      KResource getCopyPtr()
      Return a copy of this object
      protected static long getCPtr​(KResource obj)  
      KDisjunction getDisjunctionInvolving​(KTask t1, KTask t2)  
      KIntVar getDURVar()
      Return the KIntVar representing the difference between LST and EST variables
      KIntVar getESTVar()
      Return the KIntVar representing the earliest starting time of all the tasks executing on this resource
      KDisjunction getFirstDisjunctionWithUnknownStatus()  
      int getIndex()
      Return the unique index of the resource
      int getInitialCapacity()
      Return the capacity at timestep 0
      int getInitialCapacityAt​(int t)
      Return the initial resource stock at time step `t`
      boolean getIsInstantiated()
      Return true if all the tasks on this resource are fixed
      KIntVar getLCTVar()
      Return the KIntVar representing the latest completion time of all the tasks executing on this resource
      int getLocalSlack​(com.artelys.kalis.SWIGTYPE_p_p_KTask_I t1, com.artelys.kalis.SWIGTYPE_p_p_KTask_I t2)  
      int getMaxAvailability()
      Return the initial resource storage at time step 0
      int getMaxAvailabilityAt​(int t)
      Return the initial resource storage at time step t
      int getMinimumTasksDuration()
      Return the minimum tasks duration
      int getMinUsage()  
      int getMinUsageAt​(int t)
      Return the initial resource stock at time step t
      java.lang.String getName()
      Return the name of this resource
      int getNumberOfTasks()
      Return the number of tasks using this resource
      com.artelys.kalis.SWIGTYPE_p_KResource_I getResourceIPtr()  
      KSchedule getSchedule()  
      KIntVar getSlackVar()
      Return the KIntVar representing the slack for this resource
      int getStartBasedDuration​(KTask task, int start)
      When declaring a task having a start based duration (through `setStartBasedDuration` or
      `setDurationWithIdleTimes`), this method will return the actual duration of task if it begins at `start`
      timestep.

      If the `start` value is not available in the start-based duration domain, `-1` will be returned.

      KTask getTask​(int index)
      Return task with index 'index' in this resource
      KTimeTable getTimeTable()  
      boolean isIdleTimeStep​(int timestep)
      Return true IFF `timestep` is an idle timestep for this resource
      void print()
      Pretty printing of this resource
      void print​(com.artelys.kalis.SWIGTYPE_p_void ctx, com.artelys.kalis.SWIGTYPE_p_f_p_void_p_q_const__char__int pfp)
      Pretty printing of this resource with a print function pointer
      void printResourceGantt()
      Pretty printing the resource Gantt chart
      void printResourceGantt​(KSolution s, int factor)
      Pretty printing the resource Gantt chart in the console

      void printTaskGantt()
      Pretty printing the task Gantt chart
      void printTaskGantt​(KSolution s, int factor)
      Pretty printing the task Gantt chart in the console

      void setDuration​(KTask task, int duration)
      Set the duration of the task if the task is assigned to this resource.

      If the task is assigned to this resource, the duration variable will take the given `duration` value:

      `(task.assign(r) = 1) => task.duration = duration`

      Note that this is equivalent than setting start based duration with one possible value.

      void setDurationWithIdleTimes​(KTask task, int duration, KIntArray idleStarts, KIntArray idleEnds, boolean allowStartInIdle)
      Set a duration constraint conditional to some idle time windows and on the task assignment.

      If the task is assigned to this resource, the then the following statements will be enforced.

      From the given nominal `duration`, the duration variable will be constrained to take the following values:
      * `duration` if the task does not intersect any idle time window
      * `duration` increased by total length of the intersecting idle time windows

      For example, if a resource is idle on two time windows [s1, e1) and [s2, e2), then this method
      declares that the tasks intersecting those idle times windows will be extended.
      * If a task T1 starts before s1 but its `duration` make it intersect [s1, e1),
      then its duration variable will be `T1.duration = duration + e1 - s1`
      * If a task T2 starts before s1 but its updated duration make it intersect [s1, e1) and [s2, e2),
      then its duration variable will be `T2.duration = duration + (e1 - s1) + (e2 - s2)`
      * If a task T3 starts in the idle interval [s1, e1), then its duration variable
      will be `T3.duration = duration + (e1 - T3.start)`
      * If a task T4 starts in the idle interval [s1, e1) and its updated duration make it intersect [s2, e2)
      then its duration variable will be `T4.duration = duration + (e1 - T4.start) + (e2 - s2)`

      Note that if `allowStartInIdle` is false then `T3` and `T4` cases will be forbidden.
      The idle time windows can be given in any order and can be intersecting (union is made).
      Note that idle time windows are a strict end interval (end time step is not in the interval).
      If the nominal duration is dependent on the start time of the task, the `updateDurationWithIdleTimes`
      method can be used instead.



      void setInitialCapacityBetween​(int t0, int t1, int capa)
      Set the initial resource stock between time steps `t0` and `t1` to `capa`

      void setMaxAvailabilityBetween​(int t0, int t1, int capa)
      Set the initial resource stock between time steps `t0` and `t1` to `capa`

      void setMinUsageBetween​(int t0, int t1, int capa)
      Set the initial resource stock between time steps `t0` and `t1` to `capa`

      void setName​(java.lang.String name)
      Set the name of this resource
      void setResourceIPtr​(com.artelys.kalis.SWIGTYPE_p_KResource_I r)  
      void setSetupTime​(KTask task1, KTask task2, int afterT1)
      Add a coupled setup time between two tasks for the current resource.
      This means that if the two given tasks are assigned to the resource,
      then the start of the second task must be after the end of the first task
      plus the given duration :

      r.assign(t1) and r.assign(t2) => t1.end + d <= t2.start
      void setSetupTime​(KTask task1, KTask task2, int afterT1, int afterT2)
      Add a coupled setup time between two tasks for the current resource.
      This means that if the two given tasks are assigned to the resource,
      then the start of the second task must be after the end of the first task
      plus the given duration :

      r.assign(t1) and r.assign(t2) => t1.end + d <= t2.start
      void setStartBasedDuration​(KTask task, int t1, int t2, int duration)
      Set a duration computed from the value taken by the start variable if the task is assigned to this resource.

      If the task is assigned to this resource, the duration variable will take the given `duration` value if the
      start of the task is between the given interval:

      `(t1 <= task.start <= t2) and (task.assign(r) = 1) => task.duration = duration`

      This method can be called successively to specify different durations on different intervals.
      Calling successively with intersectings intervals will override existing values on the intersection.
      void updateDurationWithIdleTimes​(KTask task, int t1, int t2, boolean allowStartInIdle)
      Update the current start-based duration constraint with a new idle window.

      When having previously set a start-based duration (through `setDuration` or `setStartBasedDuration`),
      this method will update the start-based durations to simulate idle times windows.

      Warning: when adding several idle time windows, they must be added in increasing time order and time windows
      must be disjoints.
      • Methods inherited from class java.lang.Object

        clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • swigCMemOwn

        protected transient boolean swigCMemOwn
    • Constructor Detail

      • KResource

        protected KResource​(long cPtr,
                            boolean cMemoryOwn)
      • KResource

        public KResource()
        Empty constructor
      • KResource

        public KResource​(KSchedule schedule)
        Basic constructor
      • KResource

        public KResource​(KResource toCopy)
        Copy constructor
    • Method Detail

      • getCPtr

        protected static long getCPtr​(KResource obj)
      • finalize

        protected void finalize()
        Overrides:
        finalize in class java.lang.Object
      • delete

        public void delete()
      • getSchedule

        public KSchedule getSchedule()
      • getCopyPtr

        public KResource getCopyPtr()
        Return a copy of this object
      • addTask

        public void addTask​(KTask task)
      • print

        public void print()
        Pretty printing of this resource
      • print

        public void print​(com.artelys.kalis.SWIGTYPE_p_void ctx,
                          com.artelys.kalis.SWIGTYPE_p_f_p_void_p_q_const__char__int pfp)
        Pretty printing of this resource with a print function pointer
      • close

        public void close()
        Close this resource
      • getIndex

        public int getIndex()
        Return the unique index of the resource
      • getName

        public java.lang.String getName()
        Return the name of this resource
      • setName

        public void setName​(java.lang.String name)
        Set the name of this resource
      • printResourceGantt

        public void printResourceGantt​(KSolution s,
                                       int factor)
        Pretty printing the resource Gantt chart in the console

        Parameters:
        s - Given scheduling solution
        factor - distortion factor to print the Gantt in the console
      • printResourceGantt

        public void printResourceGantt()
        Pretty printing the resource Gantt chart
      • printTaskGantt

        public void printTaskGantt​(KSolution s,
                                   int factor)
        Pretty printing the task Gantt chart in the console

        Parameters:
        s - Given scheduling solution
        factor - distortion factor to print the Gantt in the console
      • printTaskGantt

        public void printTaskGantt()
        Pretty printing the task Gantt chart
      • getMinimumTasksDuration

        public int getMinimumTasksDuration()
        Return the minimum tasks duration
      • getSlackVar

        public KIntVar getSlackVar()
        Return the KIntVar representing the slack for this resource
      • getLCTVar

        public KIntVar getLCTVar()
        Return the KIntVar representing the latest completion time of all the tasks executing on this resource
      • getESTVar

        public KIntVar getESTVar()
        Return the KIntVar representing the earliest starting time of all the tasks executing on this resource
      • getDURVar

        public KIntVar getDURVar()
        Return the KIntVar representing the difference between LST and EST variables
      • getNumberOfTasks

        public int getNumberOfTasks()
        Return the number of tasks using this resource
      • getTask

        public KTask getTask​(int index)
        Return task with index 'index' in this resource
      • getIsInstantiated

        public boolean getIsInstantiated()
        Return true if all the tasks on this resource are fixed
      • getLocalSlack

        public int getLocalSlack​(com.artelys.kalis.SWIGTYPE_p_p_KTask_I t1,
                                 com.artelys.kalis.SWIGTYPE_p_p_KTask_I t2)
      • getFirstDisjunctionWithUnknownStatus

        public KDisjunction getFirstDisjunctionWithUnknownStatus()
      • getInitialCapacity

        public int getInitialCapacity()
        Return the capacity at timestep 0
      • getInitialCapacityAt

        public int getInitialCapacityAt​(int t)
        Return the initial resource stock at time step `t`
      • setInitialCapacityBetween

        public void setInitialCapacityBetween​(int t0,
                                              int t1,
                                              int capa)
        Set the initial resource stock between time steps `t0` and `t1` to `capa`

        Parameters:
        t0 - start of the interval
        t1 - end of the interval
        capa - initial resource stock
      • getMaxAvailability

        public int getMaxAvailability()
        Return the initial resource storage at time step 0
      • getMaxAvailabilityAt

        public int getMaxAvailabilityAt​(int t)
        Return the initial resource storage at time step t
      • setMaxAvailabilityBetween

        public void setMaxAvailabilityBetween​(int t0,
                                              int t1,
                                              int capa)
        Set the initial resource stock between time steps `t0` and `t1` to `capa`

        Parameters:
        t0 - start of the interval
        t1 - end of the interval
        capa - initial resource stock
      • getMinUsage

        public int getMinUsage()
      • getMinUsageAt

        public int getMinUsageAt​(int t)
        Return the initial resource stock at time step t
      • setMinUsageBetween

        public void setMinUsageBetween​(int t0,
                                       int t1,
                                       int capa)
        Set the initial resource stock between time steps `t0` and `t1` to `capa`

        Parameters:
        t0 - start of the interval
        t1 - end of the interval
        capa - initial resource storage
      • addIdleTimeSteps

        public void addIdleTimeSteps​(KIntArray idleTimeSteps)
        Add idle time steps to this resource.

        During "idle time steps", the resource does nothing, i.e. its usage
        (consumption, production, ...) for any task T is set to zero and delayed
        one time step after (if T is executed on this very time step).
      • isIdleTimeStep

        public boolean isIdleTimeStep​(int timestep)
        Return true IFF `timestep` is an idle timestep for this resource
      • setSetupTime

        public void setSetupTime​(KTask task1,
                                 KTask task2,
                                 int afterT1,
                                 int afterT2)
        Add a coupled setup time between two tasks for the current resource.
        This means that if the two given tasks are assigned to the resource,
        then the start of the second task must be after the end of the first task
        plus the given duration :

        r.assign(t1) and r.assign(t2) => t1.end + d <= t2.start
      • setSetupTime

        public void setSetupTime​(KTask task1,
                                 KTask task2,
                                 int afterT1)
        Add a coupled setup time between two tasks for the current resource.
        This means that if the two given tasks are assigned to the resource,
        then the start of the second task must be after the end of the first task
        plus the given duration :

        r.assign(t1) and r.assign(t2) => t1.end + d <= t2.start
      • setDuration

        public void setDuration​(KTask task,
                                int duration)
        Set the duration of the task if the task is assigned to this resource.

        If the task is assigned to this resource, the duration variable will take the given `duration` value:

        `(task.assign(r) = 1) => task.duration = duration`

        Note that this is equivalent than setting start based duration with one possible value.

        Parameters:
        task - The concerned task
        duration - The actual duration taken if the task is allocated to the resource

        Since:
        13.2.1
        See Also:
        setDurationWithIdleTimes
      • setStartBasedDuration

        public void setStartBasedDuration​(KTask task,
                                          int t1,
                                          int t2,
                                          int duration)
        Set a duration computed from the value taken by the start variable if the task is assigned to this resource.

        If the task is assigned to this resource, the duration variable will take the given `duration` value if the
        start of the task is between the given interval:

        `(t1 <= task.start <= t2) and (task.assign(r) = 1) => task.duration = duration`

        This method can be called successively to specify different durations on different intervals.
        Calling successively with intersectings intervals will override existing values on the intersection. Also,
        propagation should not be called between sucessive calls.
        Note: All values not included in any of the given intervals will be forbidden for the start variable.

        Parameters:
        task - The concerned task
        t1 - The first interval extremity
        t2 - The second interval extremity
        duration - The actual duration taken if the start is in the given interval

        Since:
        13.2.1
        See Also:
        setDurationWithIdleTimes setDuration
      • getStartBasedDuration

        public int getStartBasedDuration​(KTask task,
                                         int start)
        When declaring a task having a start based duration (through `setStartBasedDuration` or
        `setDurationWithIdleTimes`), this method will return the actual duration of task if it begins at `start`
        timestep.

        If the `start` value is not available in the start-based duration domain, `-1` will be returned.

        Since:
        13.2.1
        See Also:
        setDurationWithIdleTimes setDuration
      • setDurationWithIdleTimes

        public void setDurationWithIdleTimes​(KTask task,
                                             int duration,
                                             KIntArray idleStarts,
                                             KIntArray idleEnds,
                                             boolean allowStartInIdle)
        Set a duration constraint conditional to some idle time windows and on the task assignment.

        If the task is assigned to this resource, the then the following statements will be enforced.

        From the given nominal `duration`, the duration variable will be constrained to take the following values:
        * `duration` if the task does not intersect any idle time window
        * `duration` increased by total length of the intersecting idle time windows

        For example, if a resource is idle on two time windows [s1, e1) and [s2, e2), then this method
        declares that the tasks intersecting those idle times windows will be extended.
        * If a task T1 starts before s1 but its `duration` make it intersect [s1, e1),
        then its duration variable will be `T1.duration = duration + e1 - s1`
        * If a task T2 starts before s1 but its updated duration make it intersect [s1, e1) and [s2, e2),
        then its duration variable will be `T2.duration = duration + (e1 - s1) + (e2 - s2)`
        * If a task T3 starts in the idle interval [s1, e1), then its duration variable
        will be `T3.duration = duration + (e1 - T3.start)`
        * If a task T4 starts in the idle interval [s1, e1) and its updated duration make it intersect [s2, e2)
        then its duration variable will be `T4.duration = duration + (e1 - T4.start) + (e2 - s2)`

        Note that if `allowStartInIdle` is false then `T3` and `T4` cases will be forbidden.
        The idle time windows can be given in any order and can be intersecting (union is made).
        Note that idle time windows are a strict end interval (end time step is not in the interval).
        If the nominal duration is dependent on the start time of the task, the `updateDurationWithIdleTimes`
        method can be used instead.



        Parameters:
        task - The concerned task
        duration - The expected nominal duration of the task without idle times
        idleStarts - The idle time windows start (must be of same length as `idleEnds`)
        idleEnds - The idle time windows end (must be of same length as `idleStarts`)
        allowStartInIdle - If true, the `task` will be able to start in an idle time window.

        Since:
        13.2.1
        See Also:
        getStartBasedDuration setDuration
      • updateDurationWithIdleTimes

        public void updateDurationWithIdleTimes​(KTask task,
                                                int t1,
                                                int t2,
                                                boolean allowStartInIdle)
        Update the current start-based duration constraint with a new idle window.

        When having previously set a start-based duration (through `setDuration` or `setStartBasedDuration`),
        this method will update the start-based durations to simulate idle times windows.

        Warning: when adding several idle time windows, they must be added in increasing time order and time windows
        must be disjoints. If not done this way, durations might be inconsistent. Also, propagation should not be called
        between sucessive calls.



        
          resource.setDuration(task, 13);
          // Adding a first idle time window
          resource.updateDurationWithIdleTimes(task, 10, 15);
          int d = resource.getStartBasedDuration(task, 7); // d = 18
          // Adding the second idle time window
          resource.updateDurationWithIdleTimes(task, 23, 31);
          d = resource.getStartBasedDuration(task, 7); // d = 26
          

        Parameters:
        task - The concerned task
        t1 - The idle time window start
        t2 - The idle time window end
        allowStartInIdle - If true, the `task` will be able to start in the idle time window.

        Since:
        13.2.1
        See Also:
        setDuration setStartBasedDuration setDurationWithIdleTimes
      • getResourceIPtr

        public com.artelys.kalis.SWIGTYPE_p_KResource_I getResourceIPtr()
      • setResourceIPtr

        public void setResourceIPtr​(com.artelys.kalis.SWIGTYPE_p_KResource_I r)