oakca
oakca

Reputation: 1568

Variable value equals to 1 if it is utilized

I have an optimization problem which finds the minimum cost of sum of capacity[] * weight[], written with pyomo.

Schema

Mid has an initial value of 0.03. North and South have initial values of 0.

Mid, North, and South have demand values of 0.01.

A constraint which allows initial values to move around between the nodes (Mid, North, and South), which is only restricted by the capacity of the line.

I chose the capacity variables as binary, so if a line(colorful lines in figure) is used, then the capacity of that line would be equal to 1. And it creates a cost in the objective function. If it is not used then the capacity value of that line is 0.

Question: I would like to set the capacity variables as reals instead of binaries, and if they are utilized there should be a pyomo constraint which would then equalize their values to 1.

Binary Case:

# m.capacity->binary, m.flow->real
# m.flow is transfering the initial values depending on the not capped demand values.
# Lines are represented by the indices of these variables.
# If a flow variable has a value,
# then capacity value equalizes to 1 because of this constraint

def capacity_rule(m, sin, sout, tra):
    return m.flow[sin, sout, tra] <= m.capacity[sin, sout, tra]

What I want to achieve is something like following:

# m.capacity->real, m.flow->real

def capacity_rule(m, sin, sout, tra):
    return m.flow[sin, sout, tra] <= m.capacity[sin, sout, tra]

def some_rule(m, sin, sout, tra):
    if m.capacity has a value other than 0:
        return m.capacity[sin, sout, tra] == 1
    else:
        return m.capacity[sin, sout, tra] == 0

The problem is I can't really check if capacity has a value other than 0 because it is not calculated before the optimization is performed. Is there any way?

Main Idea is to implement a constraint which has the same effect of setting the capacity variable as binary in pyomo.

Here is the LP-File with 2 node system: https://justpaste.it/840wq

This would work, but then the linear problem becomes non-linear. Is there an alternative?:

def capacity_real_rule(m, sin, sout, tra):
    return m.capacity[sin, sout, tra] - m.capacity[sin, sout, tra]*m.capacity[sin, sout, tra] == 0

Upvotes: 0

Views: 283

Answers (1)

Erwin Kalvelagen
Erwin Kalvelagen

Reputation: 16724

If I am interpreting this correctly, I would suggest turning this around:

 if use=0 then flow=0
 else flow is unrestricted

This can be modeled as:

 flow <= cap*use

where cap is just exogenous (constant), use is a binary variable and flow is a continuous variable (with bounds 0 and cap).

Upvotes: 1

Related Questions