[Scip] error message on calling SCIPwriteLP
Shahin Gelareh
shahin.gelareh at gmail.com
Tue Oct 1 17:33:48 CEST 2013
Dear Gregor
Thank you for your email.
That works.
However, what I still do not understand and still challenging with is the
following:
std::vector<SCIP_CONS*> cons(3);
> for(int i = 0; i < 3; i++)
> {
> string name = "const[" + itos(i) + "]";
> SCIP_CALL(SCIPcreateConsLinear(scip, &cons[i], (const
> char*)name.c_str(), 0.0,
> NULL, NULL, 0, 3+i,
> TRUE, TRUE, TRUE, TRUE, TRUE,
> FALSE, FALSE, FALSE, FALSE, FALSE
> ));
>
> }
> SCIP_CALL(SCIPaddCoefLinear(scip, cons[0], var[0], 2));
> SCIP_CALL(SCIPaddCoefLinear(scip, cons[0], var[1], 3));
> SCIP_CALL(SCIPaddCoefLinear(scip, cons[0], var[2], 4));
>
> SCIP_CALL(SCIPaddCoefLinear(scip, cons[1], var[0], 3));
> SCIP_CALL(SCIPaddCoefLinear(scip, cons[1], var[1], 4));
> SCIP_CALL(SCIPaddCoefLinear(scip, cons[1], var[2], 5));
>
None of the " SCIP_CALL(SCIPaddCoefLinear ( ..." has an affect on the
constraints and the generated LP file turn out to be:
\ SCIP STATISTICS
\ Problem name : triKnapsack
\ Variables : 3 (3 binary, 0 integer, 0 implicit integer, 0
continuous)
\ Constraints : 0
\ Obj. scale : 1
\ Obj. offset : 0
Maximize
Obj: +1 x[0] +2 x[1] +3 x[2]
Subject to
Bounds
0 <= x[0] <= 1
0 <= x[1] <= 1
0 <= x[2] <= 1
Binaries
x[0] x[1] x[2]
End
regards,
Shahin
On Tue, Oct 1, 2013 at 4:26 PM, Gregor Hendel <hendel at zib.de> wrote:
> Hi Shahin,
>
> I haven't run your code but I think there are two issues:
> 1. In the commented part
>
> // FILE* f=fopen("tri", "w");
> //SCIP_CALL(SCIPprintOrigProblem(scip,f, "lp", 0));
>
> there is no fclose(f), that's probably why you see no output from this
> method (and the reason why you commented it out)
>
> 2. It is not possible to call SCIPwriteLP() at that point in time because
> after SCIP has returned from SCIPsolve() you're not in the solving stage
> anymore, and the LP data structure has already been cleared.
>
> I think you most likely want to use SCIPprintOrigProblem().
>
> Regards,
> Gregor
>
>
> Am 01.10.2013 15:20, schrieb Shahin Gelareh:
>
> The code is the following --very simple.
>
>> I use VS2010. The same result under Ubuntu.
>>
>
>
>> regards,
>> Shahin
>>
>>
>> /**@file triKnapsack.c
>> * @brief The first example for solving a three-constraint knapsack
>> problem
>> * @author Shahin Gelareh
>> *
>> * This example shows how to setup and solve the model using SCIP as
>> callable library.
>> *
>>
>>
>> /*--+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8----+----9----+----0----+----1----+----2*/
>>
>> #include <stdio.h>
>>
>> //#include "scip/scip.h"
>> //#include "scip/scipdefplugins.h"
>> /* include SCIP components */
>> #include "objscip/objscip.h"
>> #include "objscip/objscipdefplugins.h"
>>
>> #include <iostream>
>> #include <sstream>
>> #include <string>
>> #include <vector>
>> using namespace scip;
>> using namespace std;
>>
>> string itos(int arg) //converts an integer to a std::string
>> {
>> ostringstream buffer;
>> buffer << arg;
>> return buffer.str();
>> }
>>
>>
>> /** main method starting SCIP */
>> int main(
>> int argc, /**< number of arguments
>> from the shell */
>> char** argv /**< array of shell
>> arguments */
>> ) /*lint --e{715}*/
>> {
>> SCIP_RETCODE retcode;
>> SCIP* scip; // create the null pointer to SCIP
>> SCIP_CALL(SCIPcreate(&scip)); // initialize the SCIP instance
>>
>> SCIP_CALL(SCIPincludeDefaultPlugins(scip)); // load the default
>> plugins
>> // create an empty problem
>> SCIP_CALL(SCIPcreateProb(scip, "triKnapsack", NULL, NULL, NULL,
>> NULL, NULL, NULL, NULL
>> ));
>> SCIP_CALL(SCIPsetObjsense(scip, SCIP_OBJSENSE_MAXIMIZE));
>>
>> std::vector<SCIP_VAR*> var(3);
>> for(int i = 0; i < 3; i++)
>> {
>> string name = "x[" + itos(i) + "]";
>> SCIP_CALL(SCIPcreateVar(scip, &var[i], (const char*)name.c_str(),
>> 0.0, 1.0, i+1, SCIP_VARTYPE_BINARY,
>> TRUE, FALSE, NULL,
>> NULL, NULL, NULL, NULL));
>> SCIP_CALL(SCIPaddVar(scip, var[i]));
>> }
>> std::vector<SCIP_CONS*> cons(3);
>> for(int i = 0; i < 3; i++)
>> {
>> string name = "const[" + itos(i) + "]";
>> SCIP_CALL(SCIPcreateConsLinear(scip, &cons[i], (const
>> char*)name.c_str(), 0.0,
>> NULL, NULL, 0, 3+i,
>> TRUE, TRUE, TRUE, TRUE, TRUE,
>> FALSE, FALSE, FALSE, FALSE, FALSE
>> ));
>>
>> }
>> SCIP_CALL(SCIPaddCoefLinear(scip, cons[0], var[0], 2));
>> SCIP_CALL(SCIPaddCoefLinear(scip, cons[0], var[1], 3));
>> SCIP_CALL(SCIPaddCoefLinear(scip, cons[0], var[2], 4));
>>
>> SCIP_CALL(SCIPaddCoefLinear(scip, cons[1], var[0], 3));
>> SCIP_CALL(SCIPaddCoefLinear(scip, cons[1], var[1], 4));
>> SCIP_CALL(SCIPaddCoefLinear(scip, cons[1], var[2], 5));
>>
>> SCIP_CALL(SCIPaddCoefLinear(scip, cons[2], var[0], 4));
>> SCIP_CALL(SCIPaddCoefLinear(scip, cons[2], var[1], 5));
>> SCIP_CALL(SCIPaddCoefLinear(scip, cons[2], var[2], 6));
>> // solve
>> SCIP_CALL(SCIPsolve(scip));
>> SCIP_CALL(SCIPwriteLP(scip, "triKP"));
>> // FILE* f=fopen("tri", "w");
>>
>> //SCIP_CALL(SCIPprintOrigProblem(scip,f, "lp", 0));
>>
>>
>>
>> if( SCIPgetNSols(scip) > 0 )
>> {
>> SCIPinfoMessage(scip, NULL, "\nSolution:\n");
>> SCIP_CALL( SCIPprintSol(scip, SCIPgetBestSol(scip), NULL, FALSE) );
>> }
>>
>> SCIP_CALL( SCIPfree(&scip) );
>>
>> return SCIP_OKAY;
>> }
>>
>>
>>
>> On Tue, Oct 1, 2013 at 2:03 PM, Ambros Gleixner <gleixner at zib.de> wrote:
>>
>>> Hello Shahin,
>>>
>>> you need to give us some more details. Can you compile SCIP in debug
>>> mode (make OPT=dbg), run everything in a debugger, and send us the
>>> backtrace?
>>>
>>> Also, how and where exactly do you call SCIPwriteLP()?
>>>
>>> Best regards,
>>>
>>> Ambros
>>>
>>>
>>> Am 01.10.2013 13 <01.10.2013%2013>:41, schrieb Shahin Gelareh:
>>>
>>>> Dear SCIPers
>>>>
>>>> I build my model and it solves fine.
>>>> I need to extract the LP model to verify my mode.
>>>>
>>>> When I call it for the first time I get no output and at the same time
>>>> no error message.
>>>> The next time I run the executable it crashes :(
>>>>
>>>> Anything I am missing here?
>>>>
>>>> Best
>>>> Shahin
>>>>
>>>> --
>>>>
>>>>
>>>>
>>>>
>>>> _______________________________________________
>>>> Scip mailing list
>>>> Scip at zib.de
>>>> http://listserv.zib.de/mailman/listinfo/scip
>>>>
>>>> _______________________________________________
>>> Scip mailing list
>>> Scip at zib.de
>>> http://listserv.zib.de/mailman/listinfo/scip
>>>
>>
>>
>>
>> --
>>
>>
>>
>
>
> --
>
>
>
>
> _______________________________________________
> Scip mailing listScip at zib.dehttp://listserv.zib.de/mailman/listinfo/scip
>
>
>
> _______________________________________________
> Scip mailing list
> Scip at zib.de
> http://listserv.zib.de/mailman/listinfo/scip
>
>
--
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://listserv.zib.de/pipermail/scip/attachments/20131001/dd35eb8e/attachment.html>
More information about the Scip
mailing list