0

I'm trying to solve linear programming problem about scheduling. Each task has starting time r, time to solve task p and weight w. I have to minimize following function (C is ending time of task):

function to minimize

With data provided below Result (C-array) are:

-----RESULT-----

12.0 - C[1]  
15.0 - C[2]   
16.0 - C[3]   
29.0 - C[4] 

Which are correct when we take tasks one by one. How can I check all possible permutation and choose best one? In my case the last task should be taken first.

 function findTimetable(timeForTask :: Array{Int}, weightForTask :: Array{Int}, momentForTask:: Array{Int} )
        model :: Model = Model(with_optimizer(GLPK.Optimizer))
        _size = size(timeForTask)[1]
        @variable(model, C[1: _size] >= 0, Int)

        @objective(model, Min, sum(weightForTask[i] * C[i] for i = 1 : _size))

        for i = 1 : _size
             @constraint(model, C[i] >= momentForTask[i] + timeForTask[i])
        end
        for i = 1 : _size - 1
            @constraint(model, C[i+1] >= C[i]  + timeForTask[i+1] )
        end

        println(model)
        optimize!(model)
        println(primal_status(model))
        println(objective_value(model))
        println("-----RESULT-----")
        for i in 1:_size
            println(value(C[i]))
        end
    end


  timeForTask = [2, 3, 1, 13] #p
  weightForTask  = [1, 1, 10, 2000] #w
  momentForTask  = [10, 9, 8, 1] #r

  findTimetable(timeForTask, weightForTask, momentForTask)

Thanks in advance.

PoorGuy
  • 29
  • 8
  • 1
    I don't get why you say that your last task should be taken first as you wanted in your linear program that `C[i+1] >= C[i] + timeForTask[i+1]` which means, task `i+1` completes after task `i`. – JKHA Apr 30 '19 at 14:47

1 Answers1

0

A standard technique is to introduce a binary matrix y_ij such that task i precedes task j if y_ij=1. Then you can add restrictions

y_ij+y_ji = 1              for all i,j
C_j >= C_i+p_j-M(1-y_ij)   for all i,j

where M is a large enough constant (e.g. M=max_i r_i+sum_i p_i for release dates r_i and processing times p_i).

Marcus Ritt
  • 477
  • 5
  • 12