MATLAB: “OR” constraints lsqlin

Global Optimization Toolboxgraph theorylinear-least squareslinearizationlsqlinoptimizationOptimization Toolbox

Hello all, I'm using lsqlin to solve a graph (node-link) model, where the decision variables are the quantities in the links. I am using lsqlin() to minimize difference between the simulated flow balance in each node and a constant value generated from a function. Only problem I'm having is that I want to model the idea that the amount leaving a node is equal to the supply to that node, minus the demand; or zero otherwise (see attached screenshot). Basically, if there is less supply than demand, the nodes are still emitting outputs and if I say that:
Outflow=∑(inputs) -Demand
and
Outflow >= 0
I get an infeasible problem. However, I'm not sure how to formulate this in a way of saying the outflows will be the inputs minus demand OR zero if inputs are less than or equal to demand. Any ideas of tricks within the equality and inequality matrices? I'd like to keep using lsqlin rather than something like fmincon due to the speed of the solver but any ideas on what to do if I'm SOL with lsqlin are appreciated!

Best Answer

None of the Mathworks optimization algorithms are able to handle OR constraints, other than as general nonlinear constraints.
The efficient way to handle such constraints is to run the model multiple times, each time with a different combination of linear constraints, systematically switching between the ordinary linear constraints and possibility of the alternative constraint. Then at the end, examine all of the results and take the best version.
Any optimization routine that permitted OR constraints would have to do the same thing as I just outlined. However, I suspect it might be theoretically possible that some of the algorithms that already break the range into subregions and solve simpler problems within each subregion, might be able to detect that some of the OR constraints do not have any influence on a particular subregion they are examining and so possibly an algorithm could be written that sometimes was able to do better.
Related Question