0

Use case

This is just an easy example for understanding, how and why it is not working as expected.

There is a set of processes, which have a start and a finishing timestamp. the start timestamp of a process must be after the finishing timestamp of it's predecessor. So far, so good.


Consideration

Regarding constraints: Shouldn't it be possible to carry out more complex operations than arithmetic equations (e.g. queries and case distinctions)?

This is illustrated in the code below.

  • The standard formulation of the constraint works properly.
  • But it fails, if you put a function call into the equation.

def func(p):
    if self.start_timestamps[p] >= self.end_timestamps[p-1]:
        return 1
    return 0

# constraint for precedences of processes
for process_idx in self.processes: 
    if process_idx > 0:

        # works fine !
        model += self.start_timestamps[process_idx] >= self.end_timestamps[process_idx-1]
        
        # doesn't work, but should?!
        model += func(process_idx) == 1

Questions

  1. Are there ways to resolve that via function call? (In a more complex case, for example, you would have to make different queries and iterations within the function.)
  2. If it is not possible with PuLP, are there other OR libraries, which can process things like that?

Thanks!

FXG
  • 491
  • 3
  • 10
  • 1
    No it's not possible. And no, there is no *usable* alternative (if we ask for *black-box support*). Each of those general-purpose discrete-optimization solvers define a mathematical core-theory. You have to play by the rules implied by this. There are different concepts / solvers in discrete-opt and some are easier to use than others (e.g. Constraint Programming is more natural to non-experts compared to MILP or even worse: SAT) but of course those also behave differently (advantages and disadvantages). General tips are hard (as details matter); but consider ortools cp-sat (feels like CP). – sascha Mar 03 '21 at 11:45
  • 1
    Pyomo works with Python functions. Of course for a linear model you need to make sure things stay linear. – Erwin Kalvelagen Mar 05 '21 at 10:57

0 Answers0