I'm modeling a flow problem on graph using sage.
Once the graph was ready I've modeled a MILP problem with constraints.
I've problems having unique variables.

What I do is to use v = p.new_variable() and subsequently use the v variable in a loop iterating the edges of the graph in such as:

for origin, destination, attributes in G.edges():
    attributes['v_component_for_that_edgs'] = v[('origin', 'destination')]

But at the end some variable are duplicate!

The code producing that strange behavior is attached to this mail.
Is an error of mine or a Sage problem?

Thanks.

--
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/sage-support
URL: http://www.sagemath.org
# -*- coding: utf8 -*-
vertices = {
    'A': {'flow_balance_af': -7, 'flow_balance_fa': 12},
    'B': {'flow_balance_af': 0, 'flow_balance_fa': 0},
    'C': {'flow_balance_af': 0, 'flow_balance_fa': 0},
    'D': {'flow_balance_af': 0, 'flow_balance_fa': 0},
    'E': {'flow_balance_af': 0, 'flow_balance_fa': 0},
    'F': {'flow_balance_af': 7, 'flow_balance_fa': -12}
}
edges = [
    ('A', 'B', {'fixed_cost': 10000, 'variable_cost': 300}),
    ('A', 'E', {'fixed_cost': 20000, 'variable_cost': 150}),
    ('B', 'C', {'fixed_cost': 10000, 'variable_cost': 300}),
    ('B', 'F', {'fixed_cost': 20000, 'variable_cost': 300}),
    ('C', 'D', {'fixed_cost': 10000, 'variable_cost': 500}),
    ('C', 'A', {'fixed_cost': 20000, 'variable_cost': 350}),
    ('D', 'E', {'fixed_cost': 10000, 'variable_cost': 200}),
    ('D', 'B', {'fixed_cost': 20000, 'variable_cost': 300}),
    ('E', 'C', {'fixed_cost': 10000, 'variable_cost': 400}),
    ('F', 'A', {'fixed_cost': 5000, 'variable_cost': 400}),
    ('F', 'D', {'fixed_cost': 5000, 'variable_cost': 250}),
    ('F', 'E', {'fixed_cost': 5000, 'variable_cost': 300})
]
# Creating the graph
G = DiGraph()
G.add_vertices(vertices)
G.add_edges(edges)

p = MixedIntegerLinearProgram(maximization=False)

# Posta ad uno se l'arco viene scelto
choice_variable = p.new_variable()
p.set_binary(choice_variable)

# Flusso che viene instradato da A ad F attraverso un nodo se scelto
used_resource_variable_af = p.new_variable()
p.set_real(used_resource_variable_af)

# Flusso che viene instradato da F ad A attraverso un nodo se scelto
used_resource_variable_fa = p.new_variable()
p.set_real(used_resource_variable_fa)

# Assigning variables components to edges attributes
for o, d, a in G.edges():
    # Associamo le variabili sugli archi in modo da facilitare il lavoro dopo
    a['choice_var'] = choice_variable[(o, d)]
    a['used_res_var_af'] = used_resource_variable_af[(o, d)]
    a['used_res_var_fa'] = used_resource_variable_fa[(o, d)]

for a in G.edges():
    print a

Reply via email to