Code Monkey home page Code Monkey logo

Comments (7)

timnon avatar timnon commented on August 31, 2024

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.

from pyschedule.

sv136 avatar sv136 commented on August 31, 2024

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.

from pyschedule.

timnon avatar timnon commented on August 31, 2024

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.

from pyschedule.

sv136 avatar sv136 commented on August 31, 2024

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.

from pyschedule.

timnon avatar timnon commented on August 31, 2024

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))

from pyschedule.

sv136 avatar sv136 commented on August 31, 2024

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?

from pyschedule.

timnon avatar timnon commented on August 31, 2024

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')

from pyschedule.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.