Sagar Singh
Sagar Singh

Reputation: 11

AMPL ERROR: I am getting this error, i have mentioned and attached mod and dat files

Below are my dat and mode files for ampl. I am getting the following error:

hw3.dat, line 14 (offset 262):
b[1] already defined
context: 1 1 >>> ; <<<

hw3.dat, line 14 (offset 262):
b[1] already defined
context: 1 1 >>> ; <<<

hw3.dat, line 14 (offset 262):
b[1] already defined
context: 1 1 >>> ; <<<

hw3.dat, line 14 (offset 262):
b[1] already defined
context: 1 1 >>> ; <<<

hw3.dat, line 14 (offset 262):
b[1] already defined

MODEL FILE:

# AMPL model for the Minimum Cost Network Flow Problem
#
# By default, this model assumes that b[i] = 0, c[i,j] = 0,
# l[i,j] = 0 and u[i,j] = Infinity.
#
# Parameters not specified in the data file will get their default values.
reset;
options solver cplex;
set NODES;                        # nodes in the network
set ARCS within {NODES, NODES};   # arcs in the network
set english;
set french;
param b {NODES} default 0;        # supply/demand for node i
param c {ARCS}  default 0;        # cost of one of flow on arc(i,j)
param l {ARCS}  default 0;        # lower bound on flow on arc(i,j)
param u {ARCS}  default Infinity; # upper bound on flow on arc(i,j)
var x {ARCS};                     # flow on arc (i,j)
maximize cost: sum{(i,j) in ARCS} c[i,j] * x[i,j];  #objective: minimize 
#arc flow cost


subject to flow_balance {i in NODES}:
sum{j in NODES: (i,j) in ARCS} x[i,j] - sum{j in NODES: (j,i) in ARCS} 
x[j,i] = b[i];A
subject to capacity {(i,j) in ARCS}: l[i,j] <= x[i,j] <= u[i,j];
subject to flow_conservation {i in english}:
    sum{j in french} x[i,j] = 1;
subject to flow_bounds {(i,j) in ARCS}:
    x[i,j] = 0 || x[i,j] <= 1;
#subject to Number: {(i,j) in ARCS} x[i,j]=0 || x[i,j] = 1;



data hw3.dat
solve;
printf "The optimal pair assignments with compatibility scores are: \n";
for {i in english, j in french} {
    printf "English Child %d and French Child %d with compatibility score %d \n", i, j, c[i,j];
}
data;
set NODES :=e1 e2 e3 f1 f2 f3;
set ARCS:= (e1,f1) (e1,f2) (e1,f3) (e2,f1) (e2,f2) (e2,f3) (e3,f1) (e3,f2) (e3,f3);

set english:=e1 e2 e3;
set french:=f1 f2 f3;
param: b:=
          1 1
          1 1
          1 1
          1 1
          1 1
          1 1;
param: c l u:=
        [e1,f1] 6  0 10
        [e1,f2] 3  0 10
        [e1,f3] 2  0 10
        [e2,f1] 9  0 10
        [e2,f2] 5  0 10
        [e2,f3] 1  0 10
        [e3,f1] 4  0 10
        [e3,f2] 10 0 10
        [e3,f3] 8  0 10
 ;

It keeps saying that b is already defined, but I didn;t do it. I tried changing the name from b to some other thing, still shows the same error.

Upvotes: 0

Views: 179

Answers (1)

fdabrandao
fdabrandao

Reputation: 121

In your data file you have:

param: b:=
          1 1
          1 1
          1 1
          1 1
          1 1
          1 1;

Each line means b[1] = 1 and that is why you are getting the error "b[1] already defined context".

Since b is indexed over NODES (param b {NODES} default 0;) you should have something like the following instead:

param: b :=
          e1 1
          e2 1
          e3 1
          f1 1
          f2 1
          f3 1;

Upvotes: 0

Related Questions