define random variables t[i.j] and t[j,i]

13 views
Skip to first unread message

Shutian Li

unread,
Aug 20, 2021, 10:27:21 AM8/20/21
to AMPL Modeling Language
In my formulation, I need to define random variables t[i,j].
Here is my code: 
param t{i in 1..P, j in 1..P} = if i!=j then Uniform(30,60) else 0; 
However, this method cannot make sure t[i,j] = t[j,i], i.e., t_{12} is always not equal to t_{2,1}. 
Would you please help me on defining a symmetric parameter matrix about t? 

Thanks  

AMPL Google Group

unread,
Aug 20, 2021, 11:54:46 AM8/20/21
to AMPL Modeling Language
You can write it like this:

param t {i in 1..P, j in 1..P} =
   if i<j then Uniform(30,60) else if i>j then t[j,i] else 0;

This works because, when the indexing is {i in 1..P, j in 1..P}, t[i,j] is assigned for i<j before it is assigned for i>j. (So for example, t[1,2] is assigned first, and then[2,1] is assigned the value that t[1,2] already has.)


--
Robert Fourer
am...@googlegroups.com
{#HS:1607281580-105990#}

Shutian Li

unread,
Aug 25, 2021, 4:02:38 PM8/25/21
to AMPL Modeling Language
Awesome! Thank you so much, Robert! 
Reply all
Reply to author
Forward
0 new messages