[OS-tickets] [Optimization Services] #55: Error in gradient calculations
Optimization Services
coin-trac at coin-or.org
Sat Jan 10 06:52:54 EST 2015
#55: Error in gradient calculations
---------------------------+-----------------
Reporter: alundell | Owner:
Type: defect | Status: new
Priority: major | Milestone:
Component: other/unknown | Version:
Keywords: |
---------------------------+-----------------
I may have found a bug in the gradient calculations in OSInstance.
A minimal working example (utilizing the MINLP problem available at
http://www.gamsworld.org/minlp/minlplib2/data/osil/synthes1.osil)
-----------------------------------------------------------------------
FileUtil *fileUtil = new FileUtil();
OSiLReader *osilreader = new OSiLReader();
OSInstance *instance = NULL;
std::string filename = "synthes1.osil";
std::string osil = fileUtil->getFileAsChar(filename.c_str());
instance = osilreader->readOSiL(osil);
instance->getJacobianSparsityPattern();
std::vector<double> point(6);
point[0] = 0.0;
point[1] = 0.0;
point[2] = 1.0;
point[3] = 0.0;
point[4] = 0.0;
point[5] = 0.0;
SparseVector *sp;
sp = instance->calculateConstraintFunctionGradient(&point.at(0), 0, true);
std::cout << "Printing model:" << std::endl;
std::cout << instance->printModel() << std::endl;
std::cout << "Now printing the gradient for constraint 0" << std::endl;
for (int i = 0; i < sp->number; i++)
{
std::cout << " index: " << sp->indexes[i] << " gradient value: "
<< sp->values[i] << std::endl;
}
----------------------------------------------------------------------
When running the code above, the output is:
-----------------------------------------------------------------------
Printing model:
Objectives:
min -7*x_2 + 5*x_3 + 6*x_4 + 8*x_5 + --((10 * x_0) + (-(18 * ln( (x_1 +
1))) - (
19.2 * ln( (-x_1 + x_0 + 1)))))
Constraints:
e2 0 <= -.8*x_2 + ((.96 * ln( (-x_1 + x_0 + 1))) + (.8 * ln( (x_1 + 1))))
e3 -2 <= -1*x_2 + -2*x_5 + ((1.2 * ln( (-x_1 + x_0 + 1))) + ln( (x_1 +
1)))
e4 -1*x_0 + 1*x_1 <= 0
e5 1*x_1 + -2*x_3 <= 0
e6 1*x_0 + -1*x_1 + -2*x_4 <= 0
e7 1*x_3 + 1*x_4 <= 1
Variables:
x1: x_0 Type = C Lower Bound = 0 Upper Bound = 2
x2: x_1 Type = C Lower Bound = 0 Upper Bound = 2
x3: x_2 Type = C Lower Bound = 0 Upper Bound = 1
b4: x_3 Type = B Lower Bound = 0 Upper Bound = 1
b5: x_4 Type = B Lower Bound = 0 Upper Bound = 1
b6: x_5 Type = B Lower Bound = 0 Upper Bound = 1
Now printing the gradient for constraint 0
index: 2 gradient value: -0.8
index: 0 gradient value: -0.16
index: 1 gradient value: 0.96
-----------------------------------------------------------------------
The gradient for the first constraint is
nabla_(x_0) = 0.96/(1+x_0-x_1)
nabla_(x_1) = -0.96/(1+x_0-x_1) + 0.8/(1+x_1)
nabla_(x_2) = -0.8
so it seems the variable indexes for variables x_0 and x_1 are in the
wrong order. Or am I missing something?
I am using the Windows binaries (1.7.4), which are already a year old, so
it might be that this has been fixed already in a newer release.
--
Ticket URL: <https://projects.coin-or.org/OS/ticket/55>
Optimization Services <http://projects.coin-or.org/OS>
An interface for Web services implementing optimization.
More information about the OS-tickets
mailing list