Subscripted set in variable declaration

15 views
Skip to first unread message

Mateusz Nowak

unread,
May 18, 2017, 10:08:38 AM5/18/17
to AMPL Modeling Language
Hi, I'm trying to solve such problem using AMPL:
I have a set of Nodes and Edges that create a network. Each Edge has its own set of available wavelengths, called Lambdas (for sake of example, let's say it is 4), then each lambda can carry up to 10 Gbit/s (units are not that important here). In network are fulfilled demands between certain Nodes that have certain volume and have predefined paths able to route the traffic.

I've found a problem that I cannot solely resolve (code below):

# SETS AND PARAMETERS

# Nodes
# Consist of: a number to identify a node

param maxNode, >= 0, integer;
set Nodes=1..maxNode;

# Edges
# Consist of: nodeA and nodeB - nodes at each end of given link, and lambdas - maximum number of available wavelengths in fibre

set Edges;
param nodeA { Edges }, in Nodes;
param nodeZ { Edges }, in Nodes;

set Lambdas { Edges};
#param lambdas { Edges }, >= 0, default 1000;

# Demands
# Consist of: demand_volume - how much traffic we need to allocate, and demand_maxPath - how many paths are available to fulfill demand

set Demands;
param demand_volume { Demands }, >= 0, default 0;
param demand_maxPath { Demands }, >= 0, default 0;

# Demand_pathLinks
set Demand_pathLinks { d in Demands, dp in 1..demand_maxPath[d] } within Edges;


# VARIABLES

# x_ldp definition, cannot be higher than demand_value, cannot be lower than 0
var x_ldp {l in Lambdas[******], d in Demands, p in 1..demand_maxPath[d]} >= 0, <= demand_volume[d];
# delta_edp definition, if given link e is used in path p of demand d, then 1, else 0
var delta_edp {e in Edges, d in Demands, p in 1..demand_maxPath[d]}, binary;


# CONSTRAINTS

subject to demand_satisfaction_constraint { e in Edges, d in Demands }:
  sum {l in Lambdas[e], p in 1..demand_maxPath[d]} x_ldp[l, d, p ] = demand_volume[ d ];
  
subject to lambda_capacity_constraind {e in Edges, l in Lambdas[e] }:
  sum {d in Demands, p in 1..demand_maxPath[d]} delta_edp[e,d,p]*x_ldp[l,d,p] <= 10;

The red is part of the declaration of variable that is responsible for traffic. Basically, this variable, x_ldp, by definition in Link-path optimization method, is the amount of volume of demand d, on path p of predefined set of available paths for given demand on given wavelength (l in lambdas). But - when trying to do that, I come stand-off:
when I try to do:

l in Lambdas[e in Demand_pathLinks[d,p], d in Demands, p in 1..demand_maxPath[d], 
 
But then I got the error "e is not defined";
OR:

l in Lambdas, d in Demands, p in 1..demand_maxPath[d]

But then, I got the error, that Lambdas needs to be subscripted.

I really do will appreciate any help

Robert Fourer

unread,
May 18, 2017, 12:53:16 PM5/18/17
to am...@googlegroups.com
You should write

var x_ldp {e in Edges, l in Lambdas[e], d in Demands, p in 1..demand_maxPath[d]}
>= 0, <= demand_volume[d];

Then in the constraints you should reference x_ldp[e,l,d,p].

Bob Fourer
am...@googlegroups.com

=======

Mateusz Nowak

unread,
May 18, 2017, 1:30:44 PM5/18/17
to AMPL Modeling Language, 4...@ampl.com
Hi Bob

Thank you for your answer

I did as you suggested and it works, but I came to another problem:

When allocating traffic it gets assigned to edges that aren't in path definition. For instance, if I have Path 1 for Demand 1, connecting Node 1 to 3 via Edges 1 and 2, as in data file:

# 2 nodesparam MaxNode := 2;
 
# 3 edges
param: Edges: nodeA nodeZ :=
1 1 2
2 2 3
          3 1 3 
;

param: maxLambda := 10;

param: Demands: demand_maxPath, demand_volume:
1 1 15
;

set Demand_pathLinks[1,1] := 1 2;

Notice, that in path definition for Demand 1 there is no Edge 3. But still, it gets assigned volume, even if it shouldn't have been. I think it may be a problem with "e in Edges" declaration of x_ldp - it assignes the volume to all the Edges. Is there a way to tell the solver to use Edges, but only those, that are defined in Demand_pathLinks[d, dp]?

Mateusz Nowak

unread,
May 18, 2017, 1:54:03 PM5/18/17
to AMPL Modeling Language, 4...@ampl.com
Hi Bob, it's me, once again :P

I've just been on the phone with my friend and he said to me, that my problem may be delta_edp, but the nature of the problem remains the same - to differientate Edges that are part of the path, and those not. So, my another question is:

I know I can change delta_edp to parameter and then write manually, if edge is part of path (1 for yes, 0 otherwise), but is there a way to do it automatically, to iterate through Demand_pathLinks declaration and assign value?

In C# I think it would be like that:
foreach( d in Demands){
for(int p = 1; p < demand_maxPath + 1; p ++){
foreach( e in Demand_pathLinks[d,p]){
     delta_edp [ e, d, p] = 1;
Reply all
Reply to author
Forward
0 new messages