[FlopCpp] runtime error when defining constraints in separate
methods
Paul Huang
huangpaul99 at gmail.com
Wed May 2 23:51:19 EDT 2007
Hello group.
I create a class, which maintains a MP_model as a member. In two separate
methods of this class, I define two constraints and add them to the
MP_model. At runtime, my program generates a runtime failure. Here is the
error message
"Run-Time Check Failure #0 - The value of ESP was not properly saved across
a function call. This is usually a result
of calling a function declared with one calling convention with a function
pointer declared with a different calling
convention."
I am using Visual C++ 2005 Express. The source codes are attached below. Can
someone please point out what the problem is and how to solve it?
An interesting observation is that if I comment out a MP_constraint
declaration is method f1(). The program will run without error even this
declaration seems to have nothing to do with another method f2(), which
declare another MP_constraint and maximize a simple objective.
Thanks,
Paul
------model.hpp----------------
#ifndef _model_hpp_
#define _model_hpp_
#include "flopc.hpp"
using namespace flopc;
class model{
public:
MP_set S1, S2;
MP_variable * Y;
MP_model * mm;
model(int numS1TimeRange,
int numS2
);
~model();
void f1();
void f2();
};
#endif
----------------------------
-------model.cpp--------
#include "model.hpp"
#include <OsiCbcSolverInterface.hpp>
model::model(int numS1,
int numS2){
S1= MP_set(numS1);
S2 = MP_set(numS2);
mm= new MP_model(new OsiCbcSolverInterface);
Y=new MP_binary_variable(S1);
};
model::~model(){
delete mm;
delete Y;
};
void model::f1(){
MP_constraint c2; <===will run if this line is commented out.
};
void model::f2(){
MP_constraint c1;
c1=sum(S1, (*Y)(S1))<=2;
(*mm).add(c1);
(*mm).maximize(sum(S1, (*Y)(S1)));
cout<<"Y size: "<<(*Y).size()<<endl;
(*Y).display();
}
--------------------------
-----main.cpp-------
#include "model.hpp"
#include <iostream>
using namespace std;
void main(){
int numS1=5;
int numS2=9;
model m1(numS1, numS2);
m1.f1();
m1.f2();
}
----------------------------
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://list.coin-or.org/pipermail/flopcpp/attachments/20070502/b3c7f5fe/attachment.html
More information about the FlopCpp
mailing list