## Multiple allocation p hub median with lots of error Topic is solved

Problems with modeling
hllsyr
User Posts: 3
Joined: 3 months ago

### Multiple allocation p hub median with lots of error

Code: Select all

``````  sets
i non hub node i /1*81/

*/p city /1*81/
Alias(i,j,k,m)  ;

Parameters
a discount /0.7/
c(i,j,k,m)  /c(i,k)+c(m,j)+(a*c(k,m))/

table t(i,k) average amount of commodities from i to j
\$include C:\Users\Asus\Desktop\appendixs\Appendix3.inc
;

table d(i,j) distance between i and j
\$include C:\Users\Asus\Desktop\appendixs\Appendix1.inc
;
table c(i,k) cost between i and j
/5*d(i,j) /

table h(i,j) connection between i and j
\$include C:\Users\Asus\Desktop\appendixs\Appendix2.inc
;

Variable
z objective
p hub
y(i,k,m) i düğümünden çıkarak k ve m düğümünden geçen akış miktarı

binary variable
x(i,k)  i düğümü k hub ına atanırsa
x(k,k)  k düğümü  hub olursa

positive variable
x(i,j,k,m) the total flow for each origin–destination pair

;

Equation
obj objective function
cons1
cons2
cons3
cons4

;

obj.. z=e=sum(i,sum(j,sum(k,sum(m,(h(i,j)*x(i,j,k,m)*c(i,j,k,m))))));
cons1.. sum(k,(x(k,k)))=e=p ;

cons2(i,j).. sum(k,sum(m,(x(i,j,k,m))))=e=1   ;

cons3(i,j,k,m).. x(i,j,k,m)=l=x(k,k);

cons4(i,j,k,m)..  x(i,j,k,m)=l=x(m,m);

model project /all/;

solve project using mip minimizing z;
display z.l,x.l, y.l;``````
This is my code releated to Campbell multiple allocation p-hub median problem. can you help me to fixed errors?

abhosekar
Moderator Posts: 206
Joined: 11 months ago

### Re: Multiple allocation p hub median with lots of error

1. It is not clear what you are trying to achieve with this line.

Code: Select all

``c(i,j,k,m)  /c(i,k)+c(m,j)+(a*c(k,m))/``
First of all, it is not executed while declaring parameters. But even if it is, GAMS does not know what is c(i, k) etc.

2. It is not a good practice to have the same symbol (x) as binary as well as positive variable.
3. you can define
table c(i, j);
followed by the operation instead of doing it between / /
c(i, j) = 5*d(i, j);
4. If you define c over the domain (i, j, k, m), it makes no sense to use c(i, k) or c(m, j). From the point you declare, c should always have 4 indices.

There are many fundamental issues with the code. I suggest looking at GAMS tutorials, specially parameters.
To get your code to work, you can follow a step by step procedure. First declare parameters, populate those with values and use display. You can ignore rest of the code with \$exit.

Please note that the part where you assign values to parameters is executed sequentially. For example, you cannot use c before you assign values to it (which you do using d and you read d after you use c).

- Atharv

hllsyr
User Posts: 3
Joined: 3 months ago