CHIN JUN NAN
CHIN JUN NAN

Reputation: 1

AMPL needs to be subscripted and syntax error problems

I am newly to AMPL and I try to write some AMPL codes for my research. I have define all the variables but not sure is correct or not and I am getting error messages of :

monitoring.mod, line 19 (offset 738): v needs to be subscripted. context: var Y {d in D, v >>> in <<< V, f in F} binary; #target item need to collect

monitoring.mod, line 24 (offset 890): syntax error context: maxmimize >>> numberSpatial: <<<

This is what I get and I can solve for it.. Can anyone help me?

Thanks in advance.

mod file

# Sets
set M =1..5;        #monitoring application (m)
enter code here
set P ; #network flow between 2 nodes (p)
set Rsm {D};                #storing telemetry item inside same node (Rsm)
set v {D};                  #each telemetry item inside each node (v)    
set V;                      #total telemetry items inside the network infrastructure
set F;                      #total network flow needed to collect all items in each node
set K;                      #available space to collect the targeted telemetry item

# Parameters
param Pt{F};                #rounted path
param f{P};                 #network flow is collecting the target telemetry item

#Binary Variables
var S {m in M, d in D, p in P} binary;      #spatial dependency
var t {m in M, p in P} binary;              #temporal denpendency
var Y {d in D, v in V, f in F} binary;      #target item need to collect
var Sb {m in M, d in D, p in P} binary;     #differentiate with S

#Objective function
maxmimize numberSpatialTemporal:
sum {m in M, p in P, p in Rsm, d in D} (S[m,d,p] * t[m,p]); 

Data file

set M:=M1 M2 M3;
set D:=D1 D2 D3 D4 D5;
param P: P1 P2 P3 P4 P5 :=
     0  1  0  0  1
     1  0  1  0  1
     0  1  0  1  0
     0  0  1  0  1
     1  1  0  1  0; 
set Rsm[D1]:=v1 v2;         #possible combination of telemetry item need to be collect
set Rsm[D2]:=v1 v3;
set Rsm[D3]:=v2 v1;
set Rsm[D4]:=v2 v3;
set Rsm[D5]:=v3 v1;
set Rsm[D6]:=v3 v2;     

set v [D1]:=v1;
set v [D2]:=v2;
set v [D3]:=v3;
set v [D4]:=v1;
set v [D5]:=v2;

set V:=V1 V2 V3;

set F:=F1 F2 F3 F4 F5 F6 F7;

set K:=K1 K2;   

param : Pt :=
F1  F2  F3  F4  F5
0   1   0   0   1
1   0   1   0   1
0   1   0   1   0
0   0   1   0   1
1   1   0   1   0;  

param f:=
P1  P2  P3  P4  P5  
0   1   0   0   1
1   0   1   0   1
0   1   0   1   0
0   0   1   0   1
1   1   0   1   0;  

Upvotes: 0

Views: 426

Answers (1)

Davi Doro
Davi Doro

Reputation: 378

There are many syntax and formulation problems in the program you shared.

  • Line 3 enter code here seems like a comment, so it should begin with an #.
  • You have not declared set D.
  • Names of sets and parameters can't be used for indices. For instance, in the declaration var S {m in M, d in D, p in P} binary;, the name p is used as an index in set P, but the name p is the name of a parameter collection. Use another name, such as pp, or something.
  • Names of indices can't have duplicates in declarations. For instance, in the declaration sum {m in M, p in P, p in Rsm, d in D} (S[m,d,p] * t[m,p]); you are using p to represent both items in P and in Rsm. Use other names, such as pp for P and r for Rsm.
  • Rsm is a collection of sets, so if you want to refer to sets within that collection, you need a subscript.

You may benefit from reading some basic AMPL introductions, such as https://pifop.com/help/ampl_programs.html

Upvotes: 1

Related Questions