[Scip] error message on calling SCIPwriteLP

Gregor Hendel hendel at zib.de
Tue Oct 1 16:26:21 CEST 2013


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
>     <mailto: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 <tel: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 <mailto:Scip at zib.de>
>             http://listserv.zib.de/mailman/listinfo/scip
>
>         _______________________________________________
>         Scip mailing list
>         Scip at zib.de <mailto: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

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://listserv.zib.de/pipermail/scip/attachments/20131001/0d74ff82/attachment.html>


More information about the Scip mailing list