Is there a better way to make assignments for discrete placement? The Next CEO of Stack OverflowIs there a way to run Python on Android?What's the canonical way to check for type in Python?Nicest way to pad zeroes to a stringHow can I make a time delay in Python?Is there a way to substring a string?How to make a chain of function decorators?How to make a flat list out of list of lists?Proper way to declare custom exceptions in modern Python?Way to create multiline comments in Python?Most elegant way to check if the string is empty in Python?

How do I fit a non linear curve?

Physiological effects of huge anime eyes

TikZ: How to fill area with a special pattern?

What are the unusually-enlarged wing sections on this P-38 Lightning?

Why am I getting "Static method cannot be referenced from a non static context: String String.valueOf(Object)"?

Are the names of these months realistic?

Why do we say 'Un seul M' and not 'Une seule M' even though M is a "consonne"

Can this note be analyzed as a non-chord tone?

How did Beeri the Hittite come up with naming his daughter Yehudit?

Audio Conversion With ADS1243

Is it OK to decorate a log book cover?

Can you teleport closer to a creature you are Frightened of?

My ex-girlfriend uses my Apple ID to login to her iPad, do I have to give her my Apple ID password to reset it?

Won the lottery - how do I keep the money?

Does Germany produce more waste than the US?

Aggressive Under-Indexing and no data for missing index

Can I board the first leg of the flight without having final country's visa?

Which one is the true statement?

Where do students learn to solve polynomial equations these days?

What does "shotgun unity" refer to here in this sentence?

What would be the main consequences for a country leaving the WTO?

Is there an equivalent of cd - for cp or mv

Is French Guiana a (hard) EU border?

Free fall ellipse or parabola?



Is there a better way to make assignments for discrete placement?



The Next CEO of Stack OverflowIs there a way to run Python on Android?What's the canonical way to check for type in Python?Nicest way to pad zeroes to a stringHow can I make a time delay in Python?Is there a way to substring a string?How to make a chain of function decorators?How to make a flat list out of list of lists?Proper way to declare custom exceptions in modern Python?Way to create multiline comments in Python?Most elegant way to check if the string is empty in Python?










0















I'm trying to write a program to pair up some barges with some boats. Each barge has a certain volume. Each boat can hold up to 4 barges and push up to a certain total volume (varies by boat). The end goal is to use as few boats as possible while placing every barge.



I have tried using scipy.optimize.differential_evolution with various strategies and parameters and initial guesses. I just turn the numbers it spits out into integers so that they can be used to link to specific barges. After taking the args from the optimizer, the objective function does some work (not shown) and then sees if the conditions are satisfied and returns a value based on that. Here is some code that generally shows what I'm doing in the fobj (I don't include the full code because it is hard to understand without the structure of the classes I have set up etc):



bargeSpecsMet = True
boatSpecsMet = True
dumbBarge = 0
dumbBoat = 0

#sums up how many barges have either no assignment or more than 1 assignement
#each barge can only be in one place
for each in barges:
dumbBarge += abs(barge.numAssignments - 1)
if dumbBarge > 0:
bargeSpecsMet = False

#checks each boat to see if it over capacity
for each in boats:
if boats.totalBBLs > boats.maxBBLs:
boatSpecsMet = False
dumbBoat += 1

#returns a very large number based on how many barges aren't correct first
#does this until the barges have exactly 1 assignment each
if bargeSpecsMet == False:
return dumbBarge * 1e20

#returns a still large but smaller number based on how many boats are overcapacity
#does this until each barge is under capacity
if boatSpecsMet == False:
return dumbBoat * 1E10

#there will be more code for minimizing number of boats but i haven't gotten there yet


I used differential_evolution mainly because I'm familiar with it from using it on another project that minimized a more traditional math function. I don't think it's probably meant to be used for discrete placement of things but it sorta works. Unfortunately it doesn't want to stray far from my initial guesses. Does anyone have any tips for this? Is anyone familiar with another solver or method that would be better suited? I'm relatively new to python and also this kind of problem so I just don't know what I don't know is out there...



The only other method I've come up with so far is to brute force it by generating a combination of assignments, see if that works, if not rinse and repeat. I haven implemented it yet because I know that will take forever to find a solution.










share|improve this question


























    0















    I'm trying to write a program to pair up some barges with some boats. Each barge has a certain volume. Each boat can hold up to 4 barges and push up to a certain total volume (varies by boat). The end goal is to use as few boats as possible while placing every barge.



    I have tried using scipy.optimize.differential_evolution with various strategies and parameters and initial guesses. I just turn the numbers it spits out into integers so that they can be used to link to specific barges. After taking the args from the optimizer, the objective function does some work (not shown) and then sees if the conditions are satisfied and returns a value based on that. Here is some code that generally shows what I'm doing in the fobj (I don't include the full code because it is hard to understand without the structure of the classes I have set up etc):



    bargeSpecsMet = True
    boatSpecsMet = True
    dumbBarge = 0
    dumbBoat = 0

    #sums up how many barges have either no assignment or more than 1 assignement
    #each barge can only be in one place
    for each in barges:
    dumbBarge += abs(barge.numAssignments - 1)
    if dumbBarge > 0:
    bargeSpecsMet = False

    #checks each boat to see if it over capacity
    for each in boats:
    if boats.totalBBLs > boats.maxBBLs:
    boatSpecsMet = False
    dumbBoat += 1

    #returns a very large number based on how many barges aren't correct first
    #does this until the barges have exactly 1 assignment each
    if bargeSpecsMet == False:
    return dumbBarge * 1e20

    #returns a still large but smaller number based on how many boats are overcapacity
    #does this until each barge is under capacity
    if boatSpecsMet == False:
    return dumbBoat * 1E10

    #there will be more code for minimizing number of boats but i haven't gotten there yet


    I used differential_evolution mainly because I'm familiar with it from using it on another project that minimized a more traditional math function. I don't think it's probably meant to be used for discrete placement of things but it sorta works. Unfortunately it doesn't want to stray far from my initial guesses. Does anyone have any tips for this? Is anyone familiar with another solver or method that would be better suited? I'm relatively new to python and also this kind of problem so I just don't know what I don't know is out there...



    The only other method I've come up with so far is to brute force it by generating a combination of assignments, see if that works, if not rinse and repeat. I haven implemented it yet because I know that will take forever to find a solution.










    share|improve this question
























      0












      0








      0








      I'm trying to write a program to pair up some barges with some boats. Each barge has a certain volume. Each boat can hold up to 4 barges and push up to a certain total volume (varies by boat). The end goal is to use as few boats as possible while placing every barge.



      I have tried using scipy.optimize.differential_evolution with various strategies and parameters and initial guesses. I just turn the numbers it spits out into integers so that they can be used to link to specific barges. After taking the args from the optimizer, the objective function does some work (not shown) and then sees if the conditions are satisfied and returns a value based on that. Here is some code that generally shows what I'm doing in the fobj (I don't include the full code because it is hard to understand without the structure of the classes I have set up etc):



      bargeSpecsMet = True
      boatSpecsMet = True
      dumbBarge = 0
      dumbBoat = 0

      #sums up how many barges have either no assignment or more than 1 assignement
      #each barge can only be in one place
      for each in barges:
      dumbBarge += abs(barge.numAssignments - 1)
      if dumbBarge > 0:
      bargeSpecsMet = False

      #checks each boat to see if it over capacity
      for each in boats:
      if boats.totalBBLs > boats.maxBBLs:
      boatSpecsMet = False
      dumbBoat += 1

      #returns a very large number based on how many barges aren't correct first
      #does this until the barges have exactly 1 assignment each
      if bargeSpecsMet == False:
      return dumbBarge * 1e20

      #returns a still large but smaller number based on how many boats are overcapacity
      #does this until each barge is under capacity
      if boatSpecsMet == False:
      return dumbBoat * 1E10

      #there will be more code for minimizing number of boats but i haven't gotten there yet


      I used differential_evolution mainly because I'm familiar with it from using it on another project that minimized a more traditional math function. I don't think it's probably meant to be used for discrete placement of things but it sorta works. Unfortunately it doesn't want to stray far from my initial guesses. Does anyone have any tips for this? Is anyone familiar with another solver or method that would be better suited? I'm relatively new to python and also this kind of problem so I just don't know what I don't know is out there...



      The only other method I've come up with so far is to brute force it by generating a combination of assignments, see if that works, if not rinse and repeat. I haven implemented it yet because I know that will take forever to find a solution.










      share|improve this question














      I'm trying to write a program to pair up some barges with some boats. Each barge has a certain volume. Each boat can hold up to 4 barges and push up to a certain total volume (varies by boat). The end goal is to use as few boats as possible while placing every barge.



      I have tried using scipy.optimize.differential_evolution with various strategies and parameters and initial guesses. I just turn the numbers it spits out into integers so that they can be used to link to specific barges. After taking the args from the optimizer, the objective function does some work (not shown) and then sees if the conditions are satisfied and returns a value based on that. Here is some code that generally shows what I'm doing in the fobj (I don't include the full code because it is hard to understand without the structure of the classes I have set up etc):



      bargeSpecsMet = True
      boatSpecsMet = True
      dumbBarge = 0
      dumbBoat = 0

      #sums up how many barges have either no assignment or more than 1 assignement
      #each barge can only be in one place
      for each in barges:
      dumbBarge += abs(barge.numAssignments - 1)
      if dumbBarge > 0:
      bargeSpecsMet = False

      #checks each boat to see if it over capacity
      for each in boats:
      if boats.totalBBLs > boats.maxBBLs:
      boatSpecsMet = False
      dumbBoat += 1

      #returns a very large number based on how many barges aren't correct first
      #does this until the barges have exactly 1 assignment each
      if bargeSpecsMet == False:
      return dumbBarge * 1e20

      #returns a still large but smaller number based on how many boats are overcapacity
      #does this until each barge is under capacity
      if boatSpecsMet == False:
      return dumbBoat * 1E10

      #there will be more code for minimizing number of boats but i haven't gotten there yet


      I used differential_evolution mainly because I'm familiar with it from using it on another project that minimized a more traditional math function. I don't think it's probably meant to be used for discrete placement of things but it sorta works. Unfortunately it doesn't want to stray far from my initial guesses. Does anyone have any tips for this? Is anyone familiar with another solver or method that would be better suited? I'm relatively new to python and also this kind of problem so I just don't know what I don't know is out there...



      The only other method I've come up with so far is to brute force it by generating a combination of assignments, see if that works, if not rinse and repeat. I haven implemented it yet because I know that will take forever to find a solution.







      python python-3.x scipy






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Mar 8 at 17:33









      Ryan BoncheffRyan Boncheff

      11




      11






















          0






          active

          oldest

          votes












          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%2f55068247%2fis-there-a-better-way-to-make-assignments-for-discrete-placement%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown

























          0






          active

          oldest

          votes








          0






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes















          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%2f55068247%2fis-there-a-better-way-to-make-assignments-for-discrete-placement%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

          Thal And Out Agency railway station See also References External links Navigation menuOfficial Web Site of Pakistan RailwaysArchivedOfficial Web Site of Pakistan Railwayseeexpanding ite

          Understanding generators in Python2019 Community Moderator ElectionGenerator function not working pythonFor loop not executing two timesGenerators - Printing generated valuesWhy can a python generator only be used once?What exactly do generators do?What does the “yield” keyword do?What does “list comprehension” mean? How does it work and how can I use it?sklearn Kfold acces single fold instead of for loopIs a generator the callable? Which is the generator?Apply Border To Range Of Cells Using OpenpyxlCalling an external command in PythonWhat are metaclasses in Python?What is the difference between @staticmethod and @classmethod?Finding the index of an item given a list containing it in PythonDifference between append vs. extend list methods in PythonHow can I safely create a nested directory in Python?Does Python have a ternary conditional operator?Understanding slice notationUnderstanding Python super() with __init__() methodsDoes Python have a string 'contains' substring method?

          How can I change the color of pagination dots of UIPageControl?How to change UIPageControl dotsIs there a way to change page indicator dots colorCustomize dot with image of UIPageControl at index 0 of UIPageControlNo visible @interface for 'NSObject<PageControlDelegate>' declares the selector 'pageControlPageDidChange:'How to change the color of pagination dots in UIPageControl with a different color per pagepagecontrol indicator custom image instead of DefaultChanging the colour of UIPageControl dots in MonoTouchpagecontrol selectable page visibility color?Alternative way to load ViewControllers on a UIPageControlHow to set only layer.border-color for UIpage control dots in swiftHow can I develop for iPhone using a Windows development machine?How to change the name of an iOS app?UITableView - change section header coloruipagecontrol indicator(dot)issueCustom UIPageControl dots color not changingchange the interspace between UIPageControl dotsHow to change Status Bar text color in iOSHow can I change image tintColor in iOS and WatchKitUIPageControl dots with larger space in between each dotsHow to change the color of pagination dots in UIPageControl with a different color per page