You can specify initial values for a variable in the same way that you specify values for a parameter, following "data;". For example you could add to your data the statement
var x := 1 1 2 0 3 0 4 0 5 0 ;
or you could give the members of the set I together with the values for the variables in one statement:
var: I: x :=
1 1
2 0
3 0
4 0
5 0 ;
I see also that you define param n and give it the value 5, but do not use it in the model. If you want the set I to be the integers from 1 to n, then you can declare it by
param n integer > 0;
set I = 1..n;
and then you do not have to give values for I in the data.
Bob Fourer
From: am...@googlegroups.com [mailto:am...@googlegroups.com]
On Behalf Of Mahdi
Moeini [moeini...@gmail.com]
Sent: Friday, February 06, 2009
9:28 AM
To: am...@googlegroups.com
Subject: [AMPL 2211] How can I
give an initial solution to AMPL
from amplpy import AMPL, DataFrame
ampl = AMPL()
ampl.eval('var x{1..11, 1..168};')
df = DataFrame(('i','j'),('x'))
n, m = 11, 168
for i in range(1, n+1):
for j in range(1, m+1):
df.addRow(i, j, 10)
ampl.setData(df)
Thanks Filipe.
I used the code below (Matlab) and it worked fine:
===================================
df = DataFrame(2, 'GENS', 'PERIODS',
'u');
for i=1:10
for t=1:168
df.addRow(i,t, U(i,t));
end
end
ampl.setData(df);
==================================
However, when I read the variable before the solve command, I don't see the provided values. Is this the expected behaviour?
Kind regards,
Carlos
--
You received this message because you are subscribed to a topic in the Google Groups "AMPL Modeling Language" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/ampl/6hnr16t7Rew/unsubscribe.
To unsubscribe from this group and all its topics, send an email to ampl+uns...@googlegroups.com.
To post to this group, send email to am...@googlegroups.com.
Visit this group at https://groups.google.com/group/ampl.
For more options, visit https://groups.google.com/d/optout.
ampl.setData(df);
. Are you using an older AMPL version? You can check your AMPL version with "ampl -v" or with "option version;" in the AMPL prompt.U = ones(10, 168);
ampl.eval('var u{1..10,1..168};');
df = DataFrame(2, 'GENS', 'PERIODS', 'u');
for i=1:10
for t=1:168
df.addRow(i,t, U(i,t));
end
end
ampl.eval('display {i in 1..10, j in 1..168} u[i,j].val;'); %# displays 0's
ampl.setData(df);
ampl.eval('display {i in 1..10, j in 1..168} u[i,j].val;'); %# displays 1's
You received this message because you are subscribed to the Google Groups "AMPL Modeling Language" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ampl+uns...@googlegroups.com.
To unsubscribe from this group and stop receiving emails from it, send an email to am...@googlegroups.com.