# [AMPL 24912] Matrix 4x4

Hi, i got confused how to write the matrix 4x4 on my data in ampl software. Would you mind help by given some example
.

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)

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.

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.

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: