Pyschedule: brakes between tasks while allowing longer tasks










0















I have a following problem: I would like to schedule some meetings (tasks) using pyschedule library and allow brakes between them when cumulatively they take too long (more than 4 time slots). In the same time I would like to allow tasks taking more than the maximum 4 time slots. Let's say that I have a 1 person and 3 meetings:



person = scenario.Resource('person')
meeting1 = scenario.Task('meeting1', 1)
meeting2 = scenario.Task('meeting2', 2)
meeting3 = scenario.Task('meeting3', 5)


Then the desired solution would be for example [meeting1, meeting2, break, meeting3].
I've tried to make a restriction:



MAX_CONSECUTIVE_SLOTS = 4
for slot in range(HORIZON):
scenario += person[slot:slot + MAX_CONSECUTIVE_SLOTS + 1] <= MAX_CONSECUTIVE_SLOTS


but this works only when all meetings are no longer than MAX_CONSECUTIVE_SLOTS. I've also try to combine this condition with the number of tasks per time slice:



meeting1.count = 1
meeting2.count = 1
meeting3.count = 1

for slot in range(HORIZON):
scenario += (person[slot:slot + MAX_CONSECUTIVE_SLOTS + 1] <= MAX_CONSECUTIVE_SLOTS) or
(person['count'][slot:slot + MAX_CONSECUTIVE_SLOTS + 1] <= 1)


But person['count'][n:m] apparently means the number of tasks finished in given time slice, when I need the number of tasks overlapping this slice.



I am using mip.solve solver. Any help would be much appreciated.










share|improve this question


























    0















    I have a following problem: I would like to schedule some meetings (tasks) using pyschedule library and allow brakes between them when cumulatively they take too long (more than 4 time slots). In the same time I would like to allow tasks taking more than the maximum 4 time slots. Let's say that I have a 1 person and 3 meetings:



    person = scenario.Resource('person')
    meeting1 = scenario.Task('meeting1', 1)
    meeting2 = scenario.Task('meeting2', 2)
    meeting3 = scenario.Task('meeting3', 5)


    Then the desired solution would be for example [meeting1, meeting2, break, meeting3].
    I've tried to make a restriction:



    MAX_CONSECUTIVE_SLOTS = 4
    for slot in range(HORIZON):
    scenario += person[slot:slot + MAX_CONSECUTIVE_SLOTS + 1] <= MAX_CONSECUTIVE_SLOTS


    but this works only when all meetings are no longer than MAX_CONSECUTIVE_SLOTS. I've also try to combine this condition with the number of tasks per time slice:



    meeting1.count = 1
    meeting2.count = 1
    meeting3.count = 1

    for slot in range(HORIZON):
    scenario += (person[slot:slot + MAX_CONSECUTIVE_SLOTS + 1] <= MAX_CONSECUTIVE_SLOTS) or
    (person['count'][slot:slot + MAX_CONSECUTIVE_SLOTS + 1] <= 1)


    But person['count'][n:m] apparently means the number of tasks finished in given time slice, when I need the number of tasks overlapping this slice.



    I am using mip.solve solver. Any help would be much appreciated.










    share|improve this question
























      0












      0








      0








      I have a following problem: I would like to schedule some meetings (tasks) using pyschedule library and allow brakes between them when cumulatively they take too long (more than 4 time slots). In the same time I would like to allow tasks taking more than the maximum 4 time slots. Let's say that I have a 1 person and 3 meetings:



      person = scenario.Resource('person')
      meeting1 = scenario.Task('meeting1', 1)
      meeting2 = scenario.Task('meeting2', 2)
      meeting3 = scenario.Task('meeting3', 5)


      Then the desired solution would be for example [meeting1, meeting2, break, meeting3].
      I've tried to make a restriction:



      MAX_CONSECUTIVE_SLOTS = 4
      for slot in range(HORIZON):
      scenario += person[slot:slot + MAX_CONSECUTIVE_SLOTS + 1] <= MAX_CONSECUTIVE_SLOTS


      but this works only when all meetings are no longer than MAX_CONSECUTIVE_SLOTS. I've also try to combine this condition with the number of tasks per time slice:



      meeting1.count = 1
      meeting2.count = 1
      meeting3.count = 1

      for slot in range(HORIZON):
      scenario += (person[slot:slot + MAX_CONSECUTIVE_SLOTS + 1] <= MAX_CONSECUTIVE_SLOTS) or
      (person['count'][slot:slot + MAX_CONSECUTIVE_SLOTS + 1] <= 1)


      But person['count'][n:m] apparently means the number of tasks finished in given time slice, when I need the number of tasks overlapping this slice.



      I am using mip.solve solver. Any help would be much appreciated.










      share|improve this question














      I have a following problem: I would like to schedule some meetings (tasks) using pyschedule library and allow brakes between them when cumulatively they take too long (more than 4 time slots). In the same time I would like to allow tasks taking more than the maximum 4 time slots. Let's say that I have a 1 person and 3 meetings:



      person = scenario.Resource('person')
      meeting1 = scenario.Task('meeting1', 1)
      meeting2 = scenario.Task('meeting2', 2)
      meeting3 = scenario.Task('meeting3', 5)


      Then the desired solution would be for example [meeting1, meeting2, break, meeting3].
      I've tried to make a restriction:



      MAX_CONSECUTIVE_SLOTS = 4
      for slot in range(HORIZON):
      scenario += person[slot:slot + MAX_CONSECUTIVE_SLOTS + 1] <= MAX_CONSECUTIVE_SLOTS


      but this works only when all meetings are no longer than MAX_CONSECUTIVE_SLOTS. I've also try to combine this condition with the number of tasks per time slice:



      meeting1.count = 1
      meeting2.count = 1
      meeting3.count = 1

      for slot in range(HORIZON):
      scenario += (person[slot:slot + MAX_CONSECUTIVE_SLOTS + 1] <= MAX_CONSECUTIVE_SLOTS) or
      (person['count'][slot:slot + MAX_CONSECUTIVE_SLOTS + 1] <= 1)


      But person['count'][n:m] apparently means the number of tasks finished in given time slice, when I need the number of tasks overlapping this slice.



      I am using mip.solve solver. Any help would be much appreciated.







      python schedule






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Oct 25 '18 at 9:24









      Marta Cz-CMarta Cz-C

      3991514




      3991514






















          1 Answer
          1






          active

          oldest

          votes


















          0














          Here is a solution based on timnon's answer on Github. It is based on stress parameter, which has to be limited for any person. Each meeting increases person's stress by the amount equal to the meetings length in case of shorter meetings, or by the amount equal to the stress limit for longer meetings. Each break reduces person stress.



          from pyschedule import Scenario, solvers


          horizon = 20
          stress_limit = 4

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

          meeting1 = S.Task('meeting1', 1, stress=1)
          meeting2 = S.Task('meeting2', 2, stress=2)
          meeting3 = S.Task('meeting3', 5, stress=stress_limit)
          breaks = S.Tasks('break', schedule_cost=0, num=3, stress=-stress_limit)

          person = S.Resource('person')
          meeting1 += person
          meeting2 += person
          meeting3 += person
          breaks += person

          for t in range(horizon + 1):
          S += person['stress'][:t] <= stress_limit
          S += person['stress'][:t] >= 0

          S.clear_solution()
          S.use_flowtime_objective()

          if solvers.mip.solve(S, msg=0, kind='CBC'):
          print(S.solution())
          else:
          print('no solution found')


          Edit: this solution works well, but starts to be really slow with greater number of users and meetings.






          share|improve this answer
























            Your Answer






            StackExchange.ifUsing("editor", function ()
            StackExchange.using("externalEditor", function ()
            StackExchange.using("snippets", function ()
            StackExchange.snippets.init();
            );
            );
            , "code-snippets");

            StackExchange.ready(function()
            var channelOptions =
            tags: "".split(" "),
            id: "1"
            ;
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function()
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled)
            StackExchange.using("snippets", function()
            createEditor();
            );

            else
            createEditor();

            );

            function createEditor()
            StackExchange.prepareEditor(
            heartbeatType: 'answer',
            autoActivateHeartbeat: false,
            convertImagesToLinks: true,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: 10,
            bindNavPrevention: true,
            postfix: "",
            imageUploader:
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            ,
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            );



            );













            draft saved

            draft discarded


















            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f52985819%2fpyschedule-brakes-between-tasks-while-allowing-longer-tasks%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown

























            1 Answer
            1






            active

            oldest

            votes








            1 Answer
            1






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            0














            Here is a solution based on timnon's answer on Github. It is based on stress parameter, which has to be limited for any person. Each meeting increases person's stress by the amount equal to the meetings length in case of shorter meetings, or by the amount equal to the stress limit for longer meetings. Each break reduces person stress.



            from pyschedule import Scenario, solvers


            horizon = 20
            stress_limit = 4

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

            meeting1 = S.Task('meeting1', 1, stress=1)
            meeting2 = S.Task('meeting2', 2, stress=2)
            meeting3 = S.Task('meeting3', 5, stress=stress_limit)
            breaks = S.Tasks('break', schedule_cost=0, num=3, stress=-stress_limit)

            person = S.Resource('person')
            meeting1 += person
            meeting2 += person
            meeting3 += person
            breaks += person

            for t in range(horizon + 1):
            S += person['stress'][:t] <= stress_limit
            S += person['stress'][:t] >= 0

            S.clear_solution()
            S.use_flowtime_objective()

            if solvers.mip.solve(S, msg=0, kind='CBC'):
            print(S.solution())
            else:
            print('no solution found')


            Edit: this solution works well, but starts to be really slow with greater number of users and meetings.






            share|improve this answer





























              0














              Here is a solution based on timnon's answer on Github. It is based on stress parameter, which has to be limited for any person. Each meeting increases person's stress by the amount equal to the meetings length in case of shorter meetings, or by the amount equal to the stress limit for longer meetings. Each break reduces person stress.



              from pyschedule import Scenario, solvers


              horizon = 20
              stress_limit = 4

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

              meeting1 = S.Task('meeting1', 1, stress=1)
              meeting2 = S.Task('meeting2', 2, stress=2)
              meeting3 = S.Task('meeting3', 5, stress=stress_limit)
              breaks = S.Tasks('break', schedule_cost=0, num=3, stress=-stress_limit)

              person = S.Resource('person')
              meeting1 += person
              meeting2 += person
              meeting3 += person
              breaks += person

              for t in range(horizon + 1):
              S += person['stress'][:t] <= stress_limit
              S += person['stress'][:t] >= 0

              S.clear_solution()
              S.use_flowtime_objective()

              if solvers.mip.solve(S, msg=0, kind='CBC'):
              print(S.solution())
              else:
              print('no solution found')


              Edit: this solution works well, but starts to be really slow with greater number of users and meetings.






              share|improve this answer



























                0












                0








                0







                Here is a solution based on timnon's answer on Github. It is based on stress parameter, which has to be limited for any person. Each meeting increases person's stress by the amount equal to the meetings length in case of shorter meetings, or by the amount equal to the stress limit for longer meetings. Each break reduces person stress.



                from pyschedule import Scenario, solvers


                horizon = 20
                stress_limit = 4

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

                meeting1 = S.Task('meeting1', 1, stress=1)
                meeting2 = S.Task('meeting2', 2, stress=2)
                meeting3 = S.Task('meeting3', 5, stress=stress_limit)
                breaks = S.Tasks('break', schedule_cost=0, num=3, stress=-stress_limit)

                person = S.Resource('person')
                meeting1 += person
                meeting2 += person
                meeting3 += person
                breaks += person

                for t in range(horizon + 1):
                S += person['stress'][:t] <= stress_limit
                S += person['stress'][:t] >= 0

                S.clear_solution()
                S.use_flowtime_objective()

                if solvers.mip.solve(S, msg=0, kind='CBC'):
                print(S.solution())
                else:
                print('no solution found')


                Edit: this solution works well, but starts to be really slow with greater number of users and meetings.






                share|improve this answer















                Here is a solution based on timnon's answer on Github. It is based on stress parameter, which has to be limited for any person. Each meeting increases person's stress by the amount equal to the meetings length in case of shorter meetings, or by the amount equal to the stress limit for longer meetings. Each break reduces person stress.



                from pyschedule import Scenario, solvers


                horizon = 20
                stress_limit = 4

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

                meeting1 = S.Task('meeting1', 1, stress=1)
                meeting2 = S.Task('meeting2', 2, stress=2)
                meeting3 = S.Task('meeting3', 5, stress=stress_limit)
                breaks = S.Tasks('break', schedule_cost=0, num=3, stress=-stress_limit)

                person = S.Resource('person')
                meeting1 += person
                meeting2 += person
                meeting3 += person
                breaks += person

                for t in range(horizon + 1):
                S += person['stress'][:t] <= stress_limit
                S += person['stress'][:t] >= 0

                S.clear_solution()
                S.use_flowtime_objective()

                if solvers.mip.solve(S, msg=0, kind='CBC'):
                print(S.solution())
                else:
                print('no solution found')


                Edit: this solution works well, but starts to be really slow with greater number of users and meetings.







                share|improve this answer














                share|improve this answer



                share|improve this answer








                edited Nov 14 '18 at 16:02

























                answered Nov 6 '18 at 14:51









                Marta Cz-CMarta Cz-C

                3991514




                3991514





























                    draft saved

                    draft discarded
















































                    Thanks for contributing an answer to Stack Overflow!


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid


                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.

                    To learn more, see our tips on writing great answers.




                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function ()
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f52985819%2fpyschedule-brakes-between-tasks-while-allowing-longer-tasks%23new-answer', 'question_page');

                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown







                    Popular posts from this blog

                    Use pre created SQLite database for Android project in kotlin

                    Darth Vader #20

                    Ondo