You can assign values to decision variables in all of the same ways that you assign values to parameters. When the solver is called, AMPL sends it whatever values you have assigned to the variables, and most solvers can make use of those values in some way as initial values.
For example in section 18.4 of the AMPL book an example is shown where division by zero is avoided by assigning values to certain variables Trans[i,j] (here "limit" is a previously defined parameter indexed over {ORIG,DEST}):
let {i in ORIG, j in DEST} Trans[i,j] := limit[i,j]/2;
Because this initialization is so simple, it could also have been set in the definition of the variables:
var Trans {i in ORIG, j in DEST}:= limit[i,j]/2;
If no initial value is assigned to a variable then it will have the value 0 when sent to the solver.
Bob Fourer
From: am...@googlegroups.com [mailto:am...@googlegroups.com]
On Behalf Of Jackson
Sent: Wednesday, July 04, 2012 8:57 PM
To: am...@googlegroups.com
Subject: [AMPL 5963] Initialize variables for nonlinear problem?
Hello everyone,
How do I initialize my decision variables so that I do not run into a division by zero error for my objective function?
Thanks,
Jackson
Setting initial values does not always prevent the solver from dividing by zero. The solver may ignore the initial values, and even if it looks at the initial values it will eventually try to evaluate the objective at other points. In general, when there are integer variables the initial values do not have as much influence on the solver as when all the variables are continuous.
Thus it would be useful to know which solver you are trying to run, and where the error message appears in relation to the "solve" statement and any solver output. This will help to show whether the message is coming from AMPL, from the solver interface, or from the solver algorithm, which will provide an important clue as to what should be done.
On Behalf Of Jackson
Sent: Monday, July 09, 2012 9:27 AM
To: am...@googlegroups.com
Subject: [AMPL 5983] Re: Initialize variables for nonlinear problem?
Hello Bob,
Thanks for response and answer. I tried using both your syntax and the one in the book:
var Ship {LINKS} 〉= 0, :=1;
However, does this work for binary variables? Because I am still getting the error of 0/0, it seems that I am unable to initialize my variables.
My var declaration is:
var x{i in 1..n} binary, := 1;
And my objective function:
maximize z:
(sum{i in 1..n}(x[i]*a[i]))/ (sum{i in 1..n}(x[i]*b[i]))
My error:
error simplifying nonlinear expressions in z:
can't compute 0/0
Is there anything else that I would need to add for this formulation?
Thanks,
Jackson