Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Related tasks on different resources #63

Open
sv136 opened this issue Sep 18, 2018 · 7 comments
Open

Related tasks on different resources #63

sv136 opened this issue Sep 18, 2018 · 7 comments

Comments

@sv136
Copy link

sv136 commented Sep 18, 2018

Hello,

Is it possible to make the tasks related by precedence, to work on different resources? Something like that from your example, but vice versa

S += green_paint < green_post
# green_post will use the same resources as green_paint if there is an overlap in resource requirement
green_post += green_paint*[Alice,Bob]

Thnx!

@timnon
Copy link
Owner

timnon commented Sep 20, 2018

There is a change in the add_capacities branch which allows the follows:

S += green_paint < green_post*Alice

This would imply that green_paint is scheduled before green_post if green_post is schedule on Alice (also works with the list). The * can be interpreted in general as an if.

Is this your requirement? The branch isnt merged yet, but it is basically complete, just didnt merge yet.

@sv136
Copy link
Author

sv136 commented Sep 20, 2018

Looking at the axample, I think no. I want implement the following rules

if green_paint is scheduled on Alice then green_post should be scheduled on Bob
if green_paint is scheduled on Bob then green_post should be scheduled on Alice
green_paint < green_post

I think your code doesn't provide it.

@timnon
Copy link
Owner

timnon commented Sep 22, 2018

here is some snippet that does that:

#! /usr/bin/env python
import sys
sys.path.append('../src')
from pyschedule import Scenario, Task, Resource, solvers, plotters, alt

horizon = 10

S = Scenario('Scenario',horizon=horizon)
green_paint = S.Task('green_paint',completion_time_cost=1)
green_post = S.Task('green_post',completion_time_cost=2)

person = S.Resources('person_',num=2)

green_paint += alt(person)
green_post += alt(person)

green_post += green_paint*person

solvers.mip.solve(S, msg=1)
plotters.matplotlib.plot(S, fig_size=(10, 5))

So if green_paint is scheduled on any of the person, then green_post as well.

@sv136
Copy link
Author

sv136 commented Sep 24, 2018

It looks like initial task where both tasks are scheduled on the same resource, and moreover green_post is shceduling before green_paint. In terms of your last example I want the following

if green_paint is scheduled on person_0 then green_post should be scheduled on person_1
if green_paint is scheduled on person_1 then green_post should be scheduled on person_0
green_paint < green_post

Your code sends both tasks to the same resource.

@timnon
Copy link
Owner

timnon commented Sep 24, 2018

Ok, got it wrong, use a capacity constraint:

from pyschedule import Scenario, Task, Resource, solvers, plotters, alt

horizon = 10

S = Scenario('Scenario',horizon=horizon)
green_paint = S.Task('green_paint',completion_time_cost=1,green=1)
green_post = S.Task('green_post',completion_time_cost=2,green=1)

person = S.Resources('person',num=2)

green_paint += alt(person)
green_post += alt(person)

S += person[0]['green'] <= 1
S += person[1]['green'] <= 1

S += green_paint < green_post

solvers.mip.solve(S, msg=1)
plotters.matplotlib.plot(S, fig_size=(10, 5))

@sv136
Copy link
Author

sv136 commented Sep 25, 2018

It looks like sports-scheduling example (link), but It generates an error:
TypeError: unorderable types: NoneType() <= int()

My artificial example (isnpired by your answer) generates 'no solution':

N = 2  # NUM of Tasks
K = 2  # NUM of Legs
M = 2  # NUM of Machines
minTimeTask,maxTimeTask=2,5 # Task Execution time
TaskOfTask = []
Machines = [S.Resource('Machine{0}'.format(m)) for m in range(M)]

for n in range(N):
    subTasks = []
    for k in range(K):
        TaksName = "Task{0}_{1}".format(n+1,k+1)        
        Task = S.Task(TaksName,randint(minTimeTask,maxTimeTask), completion_time_cost=1, green = 1 )
        Task += alt( R for R in Machines )        
        subTasks.append(Task)    
    TaskOfTask.append(subTasks)
for M in Machines:
    S += M['green']<=1
        
S.use_makespan_objective()
solvers.mip.solve(S,msg=1)

What am I doing wrong?

@timnon
Copy link
Owner

timnon commented Sep 25, 2018

The following works for me? Please upgrade to the newest version 0.2.29, maybe there is some old bug. I also did some simplification regarding the definiton of the machines. The S += M['green']<=1 is too hard, i dont get a solution, so changed just for testing. Note that i define the Machines as a list and apply the ['green'] <= 1 to all of them at once.

from pyschedule import Scenario, Task, Resource, solvers, plotters, alt
from random import randint

horizon = 50
S = Scenario('Scenario',horizon=horizon)

N = 2  # NUM of Tasks
K = 2  # NUM of Legs
M = 2  # NUM of Machines
minTimeTask,maxTimeTask=2,5 # Task Execution time
TaskOfTask = []
Machines = S.Resources('Machine',num=M)

for n in range(N):
    subTasks = []
    for k in range(K):
        TaskName = "Task{0}_{1}".format(n+1,k+1)
        Task = S.Task(TaskName,randint(minTimeTask,maxTimeTask), completion_time_cost=1, green= 1)
        Task += alt(Machines)
        subTasks.append(Task)
    TaskOfTask.append(subTasks)

S += Machines['green'] <= 3

if solvers.mip.solve(S, msg=1):
	plotters.matplotlib.plot(S, fig_size=(10, 5))
else:
	print('no solution exists')

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants