Initializing help system before first use

Job-shop scheduling


Type: Job-shop scheduling
Rating: 3 (intermediate)
Description: Job-shop scheduling problem modeled with tasks and resources;
  • using the default scheduling search (jobshop2.mos)
  • or a user search strategy for tasks (jobshop2a.mos and jobshop2b.mos).
  • Model version jobshop2c.mos shows how to change the propagation algorithm for resource constraints.
File(s): jobshop2.mos, jobshop2a.mos, jobshop2b.mos, jobshop2c.mos
Data file(s): jobshop.dat


jobshop2.mos
(!****************************************************************
   CP example problems
   ===================
   
   file jobshop2.mos
   `````````````````
   Job-shob scheduling problem.
   - Default search - 

   *** This model cannot be run with a Community Licence 
       for the provided data instance ***

   (c) 2008 Artelys S.A. and Fair Isaac Corporation 

*****************************************************************!)

model "Job shop (CP)"
 uses "kalis", "mmsystem"

 parameters
  DATAFILE = "jobshop.dat"
  NJ = 6                                 ! Number of jobs
  NM = 6                                 ! Number of resources
 end-parameters

 declarations
  JOBS = 1..NJ                           ! Set of jobs
  MACH = 1..NM                           ! Set of resources
  RES: array(JOBS,MACH) of integer       ! Resource use of tasks
  DUR: array(JOBS,MACH) of integer       ! Durations of tasks

  res: array(MACH) of cpresource         ! Resources
  task: array(JOBS,MACH) of cptask       ! Tasks
 end-declarations

 initializations from "Data/"+DATAFILE
  RES DUR
 end-initializations

 HORIZON:= sum(j in JOBS, m in MACH) DUR(j,m)
 forall(j in JOBS) getend(task(j,NM)) <= HORIZON 

! Setting up the resources (capacity 1)  
 forall(m in MACH) 	  
  set_resource_attributes(res(m), KALIS_UNARY_RESOURCE, 1)

! Setting up the tasks (durations, resource used) 
 forall(j in JOBS, m in MACH)  	
  set_task_attributes(task(j,m), DUR(j,m), res(RES(j,m)))

! Precedence constraints between the tasks of every job
 forall (j in JOBS, m in 1..NM-1)
  setsuccessors(task(j,m), {task(j,m+1)})

! Solve the problem
 starttime:= gettime

 if cp_schedule(getmakespan)=0 then
  writeln("Problem is infeasible")
  exit(1)
 end-if
 
! Solution printing
 cp_show_stats
 write(gettime-starttime, "sec ")
 writeln("Total completion time: ", getsol(getmakespan))
 forall(j in JOBS) do
  write("Job ", strfmt(j,-2))
  forall(m in MACH | exists(task(j,m)))
   write(strfmt(RES(j,m),3), ":", strfmt(getsol(getstart(task(j,m))),3),  
         "-", strfmt(getsol(getend(task(j,m))),2))
  writeln
 end-do

end-model

jobshop2a.mos
(!****************************************************************
   CP example problems
   ===================
   
   file jobshop2a.mos
   ``````````````````
   Job-shob scheduling problem.
   - User branching strategy - 

   *** This model cannot be run with a Community Licence 
       for the provided data instance ***

   (c) 2008 Artelys S.A. and Fair Isaac Corporation 
       rev. Sep. 2018
*****************************************************************!)

model "Job shop (CP)"
 uses "kalis", "mmsystem"

 parameters
  DATAFILE = "jobshop.dat"
  NJ = 6                                 ! Number of jobs
  NM = 6                                 ! Number of resources
 end-parameters

 forward public function select_task(tlist: cptasklist): integer

 declarations
  JOBS = 1..NJ                           ! Set of jobs
  MACH = 1..NM                           ! Set of resources
  RES: array(JOBS,MACH) of integer       ! Resource use of tasks
  DUR: array(JOBS,MACH) of integer       ! Durations of tasks

  res: array(MACH) of cpresource         ! Resources
  task: array(JOBS,MACH) of cptask       ! Tasks
 end-declarations

 initializations from "Data/"+DATAFILE
  RES DUR
 end-initializations

 HORIZON:= sum(j in JOBS, m in MACH) DUR(j,m)
 forall(j in JOBS) getend(task(j,NM)) <= HORIZON 

! Setting up the resources (capacity 1)  
 forall(m in MACH) 	  
  set_resource_attributes(res(m), KALIS_UNARY_RESOURCE, 1)

! Setting up the tasks (durations, resource used) 
 forall(j in JOBS, m in MACH)  	
  set_task_attributes(task(j,m), DUR(j,m), res(RES(j,m)))

! Precedence constraints between the tasks of every job
 forall (j in JOBS, m in 1..NM-1)
!  getstart(task(j,m)) + DUR(j,m) <= getstart(task(j,m+1)) 
  setsuccessors(task(j,m), {task(j,m+1)})

! Branching strategy
 Strategy:=task_serialize("select_task", KALIS_MIN_TO_MAX, 
            KALIS_MIN_TO_MAX,
            union(j in JOBS, m in MACH | exists(task(j,m))) {task(j,m)})
 cp_set_branching(Strategy)

! Solve the problem
 starttime:= gettime

 if not cp_minimize(getmakespan) then
  writeln("Problem is infeasible")
  exit(1)
 end-if
 
! Solution printing
 cp_show_stats
 write(gettime-starttime, "sec ")
 writeln("Total completion time: ", getsol(getmakespan))
 forall(j in JOBS) do
  write("Job ", strfmt(j,-2))
  forall(m in MACH | exists(task(j,m)))
   write(strfmt(RES(j,m),3), ":", strfmt(getsol(getstart(task(j,m))),3),  
         "-", strfmt(getsol(getend(task(j,m))),2))
  writeln
 end-do
 
!*******************************************************************
! Task selection for branching
 public function select_task(tlist: cptasklist): integer 
  declarations
   Tset: set of integer
  end-declarations

 ! Get the number of elements of "tlist"
  listsize:= getsize(tlist)  

 ! Set of uninstantiated tasks
  forall(i in 1..listsize) 
   if not is_fixed(getstart(gettask(tlist,i))) then 
    Tset+= {i}   		
   end-if
 
  returned:= 0
 	
  ! Get a task with smallest start time domain
  smin:= min(j in Tset) getsize(getstart(gettask(tlist,j))) 
  forall(j in Tset)
   if getsize(getstart(gettask(tlist,j))) = smin then  
    returned:=j; break
   end-if

 end-function

end-model

jobshop2b.mos
(!****************************************************************
   CP example problems
   ===================
   
   file jobshop2b.mos
   ``````````````````
   Job-shob scheduling problem.
   - Scheduling search with user branching strategy - 

   *** This model cannot be run with a Community Licence 
       for the provided data instance ***

   (c) 2008 Artelys S.A. and Fair Isaac Corporation 
       Creation: 2006, rev. Sep. 2018
*****************************************************************!)

model "Job shop (CP)"
 uses "kalis", "mmsystem"

 parameters
  DATAFILE = "jobshop.dat"
  NJ = 6                                 ! Number of jobs
  NM = 6                                 ! Number of resources
 end-parameters

 forward public function select_task(tlist: cptasklist): integer
 forward public procedure print_solution

 declarations
  JOBS = 1..NJ                           ! Set of jobs
  MACH = 1..NM                           ! Set of resources
  RES: array(JOBS,MACH) of integer       ! Resource use of tasks
  DUR: array(JOBS,MACH) of integer       ! Durations of tasks

  res: array(MACH) of cpresource         ! Resources
  task: array(JOBS,MACH) of cptask       ! Tasks
 end-declarations

 initializations from "Data/"+DATAFILE
  RES DUR
 end-initializations

 HORIZON:= sum(j in JOBS, m in MACH) DUR(j,m)
 forall(j in JOBS) getend(task(j,NM)) <= HORIZON 

! Setting up the resources (capacity 1)  
 forall(m in MACH) 	  
  set_resource_attributes(res(m), KALIS_UNARY_RESOURCE, 1)

! Setting up the tasks (durations, resource used) 
 forall(j in JOBS, m in MACH)  	
  set_task_attributes(task(j,m), DUR(j,m), res(RES(j,m)))

! Precedence constraints between the tasks of every job
 forall (j in JOBS, m in 1..NM-1)
  setsuccessors(task(j,m), {task(j,m+1)})

! Branching strategy
 Strategy(1):=task_serialize("select_task", KALIS_MIN_TO_MAX, 
              KALIS_MIN_TO_MAX,
              union(j in JOBS, m in MACH | exists(task(j,m))) {task(j,m)})

(! Alternative strategy: 
 Strategy(1):=task_serialize(KALIS_SMALLEST_LCT, KALIS_MIN_TO_MAX, 
              KALIS_MIN_TO_MAX,
              union(j in JOBS, m in MACH | exists(task(j,m))) {task(j,m)})
!)

 cp_set_schedule_strategy(KALIS_INITIAL_SOLUTION, Strategy)

 cp_set_solution_callback("print_solution")   ! Define solution callback   
 setparam("KALIS_VERBOSE_LEVEL", 2)           ! Enable solver output

! Solve the problem
 starttime:= gettime 

 if cp_schedule(getmakespan)=0 then
  writeln("Problem is infeasible")
  exit(1)
 end-if
 
! Solution printing
 cp_show_stats
 write(gettime-starttime, "sec ")
 writeln("Total completion time: ", getsol(getmakespan))
 forall(j in JOBS) do
  write("Job ", strfmt(j,-2))
  forall(m in MACH | exists(task(j,m)))
   write(strfmt(RES(j,m),3), ":", strfmt(getsol(getstart(task(j,m))),3),  
         "-", strfmt(getsol(getend(task(j,m))),2))
  writeln
 end-do

!*******************************************************************
! Task selection for branching
 public function select_task(tlist: cptasklist): integer 
  declarations
   Tset: set of integer
  end-declarations

 ! Get the number of elements of "tlist"
  listsize:= getsize(tlist)  

 ! Set of uninstantiated tasks
  forall(i in 1..listsize) 
   if not is_fixed(getstart(gettask(tlist,i))) then 
    Tset+= {i}   		
   end-if
 
  returned:= 0
 	
  ! Get a task with smallest start time domain
  smin:= min(j in Tset) getsize(getstart(gettask(tlist,j))) 
  forall(j in Tset)
   if getsize(getstart(gettask(tlist,j))) = smin then  
    returned:=j; break
   end-if

 end-function
 
 public procedure print_solution
  writeln("(", gettime-starttime, "sec) Solution found with makespan = ",
          getsol(getmakespan))
 end-procedure

end-model

jobshop2c.mos
(!****************************************************************
   CP example problems
   ===================
   
   file jobshop2c.mos
   `````````````````
   Job-shob scheduling problem.
   - Selecting the propagation algorithm - 

   *** This model cannot be run with a Community Licence 
       for the provided data instance ***

   (c) 2008 Artelys S.A. and Fair Isaac Corporation 

*****************************************************************!)

model "Job shop (CP)"
 uses "kalis", "mmsystem"

 parameters
  ALG = KALIS_TASK_INTERVALS             ! or: KALIS_DISJUNCTIONS
  DATAFILE = "jobshop.dat"
  NJ = 6                                 ! Number of jobs
  NM = 6                                 ! Number of resources
 end-parameters

 declarations
  JOBS = 1..NJ                           ! Set of jobs
  MACH = 1..NM                           ! Set of resources
  RES: array(JOBS,MACH) of integer       ! Resource use of tasks
  DUR: array(JOBS,MACH) of integer       ! Durations of tasks

  res: array(MACH) of cpresource         ! Resources
  task: array(JOBS,MACH) of cptask       ! Tasks
 end-declarations

 initializations from "Data/"+DATAFILE
  RES DUR
 end-initializations

 HORIZON:= sum(j in JOBS, m in MACH) DUR(j,m)
 forall(j in JOBS) getend(task(j,NM)) <= HORIZON 

! Setting up the resources (capacity 1)  
 forall(m in MACH) 	  
  set_resource_attributes(res(m), KALIS_UNARY_RESOURCE, 1, ALG)

! Setting up the tasks (durations, resource used) 
 forall(j in JOBS, m in MACH)  	
  set_task_attributes(task(j,m), DUR(j,m), res(RES(j,m)))

! Precedence constraints between the tasks of every job
 forall (j in JOBS, m in 1..NM-1)
  setsuccessors(task(j,m), {task(j,m+1)})

! Solve the problem
 starttime:= gettime

 if cp_schedule(getmakespan)=0 then
  writeln("Problem is infeasible")
  exit(1)
 end-if
 
! Solution printing
 cp_show_stats
 write(gettime-starttime, "sec ")
 writeln("Total completion time: ", getsol(getmakespan))
 forall(j in JOBS) do
  write("Job ", strfmt(j,-2))
  forall(m in MACH | exists(task(j,m)))
   write(strfmt(RES(j,m),3), ":", strfmt(getsol(getstart(task(j,m))),3),  
         "-", strfmt(getsol(getend(task(j,m))),2))
  writeln
 end-do

end-model

© 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.