Matrix 4x4

63 views
Skip to first unread message

Mifthahul Janna Rosyid

unread,
Nov 29, 2023, 10:22:44 PM11/29/23
to AMPL Modeling Language
Hi, i got confused how to write the matrix 4x4 on my data in ampl software. Would you mind help by given some example
.function a.png
the cost(ijkt) stands for cost  transportation  of commodity k from node i to node j in month t and the F(ijkt) stands for  flow of commodity k from node i to node j in month t (metric ton)

Sarah O

unread,
Nov 30, 2023, 9:23:12 AM11/30/23
to AMPL Modeling Language
Hi
Do you mean 4x4 matrix or you mean a 4-dimensional matrix. I think you mean the latter.
Here is how if I understood correctly:

#data file, change values below as you want
param nK:= 3; #number of commodoties
param nN:= 4; #number of nodes
param nT:= 8; #number of time instances/values

#model file
param nK>=0;
param nN>=0;
param nT>=0;

set K:= 1..nK;
set N:= 1..nN;
set T:= 1..nT;


param cost{i in N, j in N, k in K, t in T} >=0;
var F{i in N, j in N, k in K, t in T} >=0 binary;
var FCR>=0;

#objective function here

#constraints here

since the equation for the objective is fractional you need to manipulate it. I had a similar issue so I cross-multiplied so you will have
FCR x sum{F_ijkt} = sum{cost_ijkt}x  F_ijkt
The left hand side of the equation is then quadratic where you multiply two variables (I assumed the F_ijkt is binary indicating if the i,j path is used, this also makes the model easier). Look for the linearization of a product of a binary variable times a coninuous variable and then add your remaining constraints and you should be able to complete it.


All the best. 

Mifthahul Janna Rosyid

unread,
Dec 21, 2023, 1:03:02 PM12/21/23
to AMPL Modeling Language
sorry for the misunderstanding. i am confused in writing the parameter F_ijkt in ampl data. Since i know F_ijkt has four set : i, j, k, and t.

AMPL Google Group

unread,
Dec 26, 2023, 5:21:31 PM12/26/23
to AMPL Modeling Language
There are several ways to specify "four-dimensional" data for a parameter that is indexed over four sets. They are described in two sections of the AMPL book:
If you try one of these ways, and run into trouble, you can post a question here. Be sure to show the table that you have written and the text of all error messages.


--
Robert Fourer

We're switching to a new, enhanced user forum.
Join it now at discuss.ampl.com.
{#HS:2437571540-120906#}
On Thu, Dec 21, 2023 at 6:03 PM UTC, AMPL Modeling Language <am...@googlegroups.com> wrote:
sorry for the misunderstanding. i am confused in writing the parameter F_ijkt in ampl data. Since i know F_ijkt has four set : i, j, k, and t.

Reply all
Reply to author
Forward
0 new messages