How to express the multiplication in AMPL?

1,633 views
Skip to first unread message

srestha....@gmail.com

unread,
Jun 30, 2016, 3:58:36 AM6/30/16
to AMPL Modeling Language

I have an optimization problem : The variables and the given constants are in Matrix/vector form.

How can I express T_i and A_i in AMPL language?

Robert Fourer

unread,
Jul 2, 2016, 1:20:00 PM7/2/16
to am...@googlegroups.com

It's necessary to use scalar rather than vector-matrix notation in AMPL.  You could define C, I, and E by

   param C {1..N, 1..M};
   param I {1..M, 1..M};
   param E {1..M};

Then the expression for C_[i]E is

   sum {j in 1..M} C[i,j] * E[j]

This can be used in the expression for T_i.  To get the log_2 function of an expression you need to compute the log of the expression divided by log(2).  (I am writing C, I, and E as params here though perhaps some of them should be vars; you don't distinguish parameters from variables in your question.)

The expression for A_i does not seem right to me, because I_[i] which is 1 x M is multiplying C which is N x M.

Bob Fourer
am...@googlegroups.com


srestha....@gmail.com

unread,
Jul 3, 2016, 12:21:05 AM7/3/16
to AMPL Modeling Language
Dear Bob, 

Thank you very much for your reply. Sorry for the mistype. Here is my problem that I want to solve in AMPL.
Please help me out.
OP.pdf

srestha....@gmail.com

unread,
Jul 3, 2016, 12:45:00 AM7/3/16
to AMPL Modeling Language
Is it a correct formulation?

Is it correct?

The .mod, .data and .run file are give below, How do I define the variable related to JJ and TT

OP.mod

reset;

param N;

param M;

set NSET := {1..N};

set MSET := {1..M};

param I{NSET,NSET};

param E{MSET};

param P;

param G;


var C{NSET, MSET} binary;

var J{n in NSET}=sum{n in NSET, m in MSET}I[n,m]C[n,m]C[n,m];

var T{n in NSET}=(sum {m in MSET}C[n,m]E[m])log(1+P/(J[n]G(sum {m in MSET}C[n,m]*E[m])))/log(2)


maximize OBJ: sum {n in NSET} T[n];



OP.dat

data;

param N=5;

param M=20;

param I{N,N};

param E:= 1 1 2 1 3 1 4 1 5 1 6 1 7 1 8 1 9 1 10 1 11 1 12 1 13 1 14 1 15 1 16 1 17 1 18 1 19 1 20 1;

param P=10;

param G=1e-08;

param I : 1 2 3 4 5:= 1 0 1274 1183 1143 1267 2 1197 0 1050 1312 1089 3 1266 1174 0 1090 1190 4 1097 1105 1250 0 1135 5 1097 1105 1250 1201 0;



OP.run

model DCNDC.mod;

data DCNDC.dat;

option solver knito;

solve;

option display_1col 64;


On Thursday, June 30, 2016 at 4:58:36 PM UTC+9, srestha....@gmail.com wrote:

Robert Fourer

unread,
Jul 9, 2016, 7:10:10 AM7/9/16
to am...@googlegroups.com
I think what you are looking for is

var J {i in 1..N} = sum {j in 1..N, k in 1..M} I[i,j] * C[j,k] * C[i,k];

Note that you need to use the operator * for multiplication. Also it's not necessary to define NSET and MSET to stand for 1..N and 1..M, since notation like 1..N can be used directly in AMPL expressions.

Bob Fourer
am...@googlegroups.com

=======

From: am...@googlegroups.com [mailto:am...@googlegroups.com] On Behalf Of srestha....@gmail.com
Sent: Saturday, July 2, 2016 11:45 PM
To: AMPL Modeling Language
Subject: [AMPL 12261] Re: How to express the multiplication in AMPL?

Is it a correct formulation?

The .mod, .data and .run file are give below, How do I define the variable related to JJ and TT

OP.mod
Reply all
Reply to author
Forward
0 new messages