"OR" constraints lsqlin
Show older comments
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!
2 Comments
Is the "difference between the simulated flow balance in each node and a constant value" the same as
| ∑(inputs)-Outflow-Demand |
If not, what is the objective function, exactly?
Jacob Tracy
on 15 Aug 2018
Accepted Answer
More Answers (1)
You could try using ga() instead with the constraints
max( ∑(inputs) -Demand -Outflow , -Outflow) = 0
This is equivalent to
Outflow = max( ∑(inputs) -Demand , 0)
which I think is what you want.
2 Comments
Jacob Tracy
on 16 Aug 2018
No, that's very inefficient. First, do not use evalin to pass A and B to your objective. Use anonymous or nested functions to pass fixed parameters.
Secondly, get rid of the for-loop. Compute the objective value in one line,
y=norm(A*x-B);
Thirdly, use ga, not fmincon. Your constraints are not differentiable.
Fourthly, it might help in terms of speed and reliability to include certain judicious x in your initial population, which are likely to be near the global solution. For example, you could include the solution of the relaxed linear problem
Outflow >= ∑(inputs) -Demand
Outflow >= 0
which is easily obtained with lsqlin.
Categories
Find more on Linear Least Squares in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!