0

I have an equation on the form A^n*b =e= c where A is a matrix and b & c are column vectors.

n is a fixed number for my model determined by a constant. It will most likely be in the hundreds and be changed for different solutions.

A is a matrix of variables, b & c are constants.

How can I formulate A^n*b =e= c in gams?

Optionally: the model that lead me to this is that I have a graph with a connectivity matrix con(x,x2) denoting the connectivity between x and x2 when x and x2 are connected. I would like to calculate the connection between 2 arbitrary nodes, the connectivity between 2 nodes x to x2 is the sum of the connectivity for all paths from x to x2. the connectivity for a path is the product of all connections along the path. Is there a smarter way to formulate this constraint so that I don't have to do matrix exponentiation?

A is not symmetric or invertible but is positive Semidefinite.

Bomaz
  • 1,871
  • 1
  • 17
  • 22

1 Answers1

0

You need to define your data in terms of sets and parameters first. Follow this link for more information about the data structure in GAMS: http://www.gams.com/latest/docs/userguides/userguide/_u_g__data_entry.html

Start by defining the sets and parameters of your problem, supposing you have 100 vertices, you can declare x like this for example:

Set x /x1*x100/;
alias(x,x2);

Because you will need to use the same set twice in your matrix, you have to define an alias so that x2 is interpreted by GAMS as the same as x in your model.

Then, declare n and b as parameters, you can do it like this:

Parameter 
 n /200/
 c /100/;
Parameter b(x)
/
x1 3
x2 43
...
x100 23
/;

Note that parameters and variables with more than one value (i.e vectors or matrices) have to be defined over a previously defined set in GAMS. This is why b is defined over set x, think of x like indices of your vectors/matrices.

Declaration of A will have the form:

Variable A(x,x2);

Now you can define your equation using these sets, parameters and variables:

eq(x,x2) .. power(A(x,x2),n) * B(x2) =e=  c;

Of course, you will still need to pick a suitable solver (NLP) and define an objective function, but this is how you would model the equation you want and variables for it.

Jon Cardoso-Silva
  • 991
  • 11
  • 25
  • Doesn't power just do exponentiation aka A_(x,x2)^n rather than actually performing matrix multiplication on all of A which is a vastly different result? – Bomaz Jan 22 '17 at 20:08
  • Yes, that is absolutely true. GAMS is really not ideal for doing matrix multiplications AFAIK, but there are a few utilities that might help, such as matrix inversion and eigenvectors. I thought I would mention them in case you haven't seen them. https://www.gams.com/latest/docs/userguides/mccarl/matrix_utilities.htm I'm sure what you are asking is possible, but I have no idea how. – Martin Bonde Jan 24 '17 at 08:30
  • "I would like to calculate the connection between 2 arbitrary nodes, the connectivity between 2 nodes x to x2 is the sum of the connectivity for all paths from x to x2. the connectivity for a path is the product of all connections along the path. Is there a smarter way to formulate this constraint so that I don't have to do matrix exponentiation?" It sounds like this could be accomplished pretty easily with a combination of loops and sums. – Martin Bonde Jan 24 '17 at 08:34