Exemple #1
0
/** gets bounding variable y of variable bound constraint lhs <= x + c*y <= rhs */
JNIEXPORT
jlong JNISCIPCONSVARBOUND(getVbdvarVarbound)(
   JNIEnv*               env,                /**< JNI environment variable */
   jobject               jobj,               /**< JNI class pointer */
   jlong                 jscip,              /**< SCIP data structure */
   jlong                 jcons               /**< constraint data */
   )
{
   SCIP* scip;
   SCIP_CONS* cons;
   SCIP_VAR* var;

   /* convert JNI pointer into C pointer */
   scip = (SCIP*) (size_t) jscip;
   assert(scip != NULL);

   /* convert JNI pointer into C pointer */
   cons = (SCIP_CONS*) (size_t) jcons;
   assert(cons != NULL);

   var = SCIPgetVbdvarVarbound(scip, cons);

   return (jlong)(size_t)var;
}
Exemple #2
0
/** writes problem to file */
SCIP_RETCODE SCIPwriteCcg(
   SCIP*                 scip,               /**< SCIP data structure */
   FILE*                 file,               /**< output file, or NULL if standard output should be used */
   const char*           name,               /**< problem name */
   SCIP_Bool             transformed,        /**< TRUE iff problem is the transformed problem */
   SCIP_VAR**            vars,               /**< array with active variables ordered binary, integer, implicit, continuous */
   int                   nvars,              /**< number of active variables in the problem */
   SCIP_CONS**           conss,              /**< array with constraints of the problem */
   int                   nconss,             /**< number of constraints in the problem */
   SCIP_RESULT*          result              /**< pointer to store the result of the file writing call */
   )
{  /*lint --e{715}*/
   int c;
   int v;
   int i;

   SCIP_CONSHDLR* conshdlr;
   const char* conshdlrname;
   SCIP_CONS* cons;

   SCIP_VAR** consvars;
   SCIP_Real* consvals;
   int nconsvars;

   SparseGraph G;

   assert( scip != NULL );
   assert( nvars >= 0 );

   /* initialize graph */
   SCIP_CALL( initGraph(scip, &G, (unsigned int) nvars, 10) );

   /* check all constraints */
   for( c = 0; c < nconss; ++c)
   {
      cons = conss[c];
      assert( cons != NULL);

      /* in case the transformed is written only constraint are posted which are enabled in the current node */
      assert(!transformed || SCIPconsIsEnabled(cons));

      conshdlr = SCIPconsGetHdlr(cons);
      assert( conshdlr != NULL );

      conshdlrname = SCIPconshdlrGetName(conshdlr);
      assert( transformed == SCIPconsIsTransformed(cons) );

      if( strcmp(conshdlrname, "linear") == 0 )
      {  
         consvars = SCIPgetVarsLinear(scip, cons);
         nconsvars = SCIPgetNVarsLinear(scip, cons);
         assert( consvars != NULL || nconsvars == 0 );

         if( nconsvars > 0 ) 
         { 
            SCIP_CALL( handleLinearCons(scip, SCIPgetVarsLinear(scip, cons), SCIPgetValsLinear(scip, cons),
                  SCIPgetNVarsLinear(scip, cons), transformed, &G) );
         }
      }
      else if( strcmp(conshdlrname, "setppc") == 0 )
      {
         consvars = SCIPgetVarsSetppc(scip, cons);
         nconsvars = SCIPgetNVarsSetppc(scip, cons);
         assert( consvars != NULL || nconsvars == 0 );

         if( nconsvars > 0 ) 
         {
            SCIP_CALL( handleLinearCons(scip, consvars, NULL, nconsvars, transformed, &G) );
         }
      }
      else if( strcmp(conshdlrname, "logicor") == 0 )
      {  
         consvars = SCIPgetVarsLogicor(scip, cons);
         nconsvars = SCIPgetNVarsLogicor(scip, cons);
         assert( consvars != NULL || nconsvars == 0 );

         if( nconsvars > 0 ) 
         { 
            SCIP_CALL( handleLinearCons(scip, SCIPgetVarsLogicor(scip, cons), NULL, SCIPgetNVarsLogicor(scip, cons), transformed, &G) );
         }
      }
      else if( strcmp(conshdlrname, "knapsack") == 0 )
      {
         SCIP_Longint* w;

         consvars = SCIPgetVarsKnapsack(scip, cons);
         nconsvars = SCIPgetNVarsKnapsack(scip, cons);
         assert( consvars != NULL || nconsvars == 0 );

         /* copy Longint array to SCIP_Real array */
         w = SCIPgetWeightsKnapsack(scip, cons);
         SCIP_CALL( SCIPallocBufferArray(scip, &consvals, nconsvars) );
         for( v = 0; v < nconsvars; ++v )
            consvals[v] = (SCIP_Real)w[v];

         if( nconsvars > 0 ) 
         { 
            SCIP_CALL( handleLinearCons(scip, consvars, consvals, nconsvars, transformed, &G) );
         }
         SCIPfreeBufferArray(scip, &consvals);
      }
      else if( strcmp(conshdlrname, "varbound") == 0 )
      {
         SCIP_CALL( SCIPallocBufferArray(scip, &consvars, 2) );
         SCIP_CALL( SCIPallocBufferArray(scip, &consvals, 2) );

         consvars[0] = SCIPgetVarVarbound(scip, cons);
         consvars[1] = SCIPgetVbdvarVarbound(scip, cons);

         consvals[0] = 1.0;
         consvals[1] = SCIPgetVbdcoefVarbound(scip, cons);

         SCIP_CALL( handleLinearCons(scip, consvars, consvals, 2, transformed, &G) );

         SCIPfreeBufferArray(scip, &consvars);
         SCIPfreeBufferArray(scip, &consvals);
      }
      else
      {
         SCIPwarningMessage(scip, "constraint handler <%s> cannot print requested format\n", conshdlrname );
         SCIPinfoMessage(scip, file, "\\ ");
         SCIP_CALL( SCIPprintCons(scip, cons, file) );
         SCIPinfoMessage(scip, file, ";\n");
      }
   }

   /* output graph */
   SCIPinfoMessage(scip, file, "c graph generated from %s\n", name);
   SCIPinfoMessage(scip, file, "p edge %d %d\n", nvars, G.m);

   for( i = 0; i < nvars; ++i )
   {
      unsigned int k;
      int a;

      k = 0;
      a = G.A[i][k];
      while( a >= 0 )
      {
         /* only output edges from lower to higher number */
         if( i < a )
         {
            /* note: node numbers start with 1 in the DIMACS format */
            SCIPinfoMessage(scip, file, "e %d %d %f\n", i+1, a+1, G.W[i][k]);
         }

         a = G.A[i][++k];
         assert( k <= G.size[i] );
      }
      assert( k == G.deg[i] );
   }

   freeGraph(scip, &G);

   *result = SCIP_SUCCESS;

   return SCIP_OKAY;
}
Exemple #3
0
/** writes problem to file */
SCIP_RETCODE SCIPwritePpm(
   SCIP*                 scip,               /**< SCIP data structure */
   FILE*                 file,               /**< output file, or NULL if standard output should be used */
   const char*           name,               /**< problem name */
   SCIP_READERDATA*      readerdata,         /**< information for reader */
   SCIP_Bool             transformed,        /**< TRUE iff problem is the transformed problem */
   SCIP_VAR**            vars,               /**< array with active variables ordered binary, integer, implicit, continuous */
   int                   nvars,              /**< number of active variables in the problem */
   SCIP_CONS**           conss,              /**< array with constraints of the problem */
   int                   nconss,             /**< number of constraints in the problem */
   SCIP_RESULT*          result              /**< pointer to store the result of the file writing call */
   )
{  /*lint --e{715}*/
   int c;
   int v;
   int i;

   int linecnt;
   char linebuffer[PPM_MAX_LINELEN];

   SCIP_CONSHDLR* conshdlr;
   const char* conshdlrname;
   SCIP_CONS* cons;

   SCIP_VAR** consvars;
   SCIP_Real* consvals;
   int nconsvars;
   int i_max = 1;
   SCIP_Real maxcoef = 0;
   SCIP_Bool printbool = FALSE;

   assert( scip != NULL );
   assert(readerdata != NULL);

   /* print statistics as comment to file */
   if(readerdata->rgb_ascii)
      SCIPinfoMessage(scip, file, "P6\n");
   else
      SCIPinfoMessage(scip, file, "P3\n");
   SCIPinfoMessage(scip, file, "# %s\n", name);
   SCIPinfoMessage(scip, file, "%d %d\n", nvars, nconss);
   SCIPinfoMessage(scip, file, "255\n");

   clearLine(linebuffer, &linecnt);

   if(!(readerdata->rgb_relativ))
   {
      i_max = 2;
   }

   for(i = 0; i < i_max; ++i)
   {
      if(i)
      {
         printbool = TRUE;
         SCIPdebugPrintf("Maximal coefficient = %g\n", maxcoef);
      }


     for(c = 0; c < nconss; ++c)
     {
        cons = conss[c];
        assert( cons != NULL);

        /* in case the transformed is written only constraint are posted which are enabled in the current node */
        assert(!transformed || SCIPconsIsEnabled(cons));

        conshdlr = SCIPconsGetHdlr(cons);
        assert( conshdlr != NULL );

        conshdlrname = SCIPconshdlrGetName(conshdlr);
        assert( transformed == SCIPconsIsTransformed(cons) );

        if( strcmp(conshdlrname, "linear") == 0 )
        {
           consvars = SCIPgetVarsLinear(scip, cons);
           nconsvars = SCIPgetNVarsLinear(scip, cons);
           assert( consvars != NULL || nconsvars == 0 );

           if( nconsvars > 0 )
           {
              SCIP_CALL( printLinearCons(scip, file, readerdata, consvars, SCIPgetValsLinear(scip, cons),
                    nconsvars, nvars, transformed, &maxcoef, printbool) );
           }
        }
        else if( strcmp(conshdlrname, "setppc") == 0 )
        {
           consvars = SCIPgetVarsSetppc(scip, cons);
           nconsvars = SCIPgetNVarsSetppc(scip, cons);
           assert( consvars != NULL || nconsvars == 0 );

           if( nconsvars > 0 )
           {
              SCIP_CALL( printLinearCons(scip, file, readerdata, consvars, NULL,
                    nconsvars, nvars, transformed, &maxcoef, printbool) );
           }
        }
        else if( strcmp(conshdlrname, "logicor") == 0 )
        {
           consvars = SCIPgetVarsLogicor(scip, cons);
           nconsvars = SCIPgetNVarsLogicor(scip, cons);
           assert( consvars != NULL || nconsvars == 0 );

           if( nconsvars > 0 )
           {
              SCIP_CALL( printLinearCons(scip, file, readerdata, consvars, NULL,
                    nconsvars, nvars, transformed, &maxcoef, printbool) );
           }
        }
        else if( strcmp(conshdlrname, "knapsack") == 0 )
        {
           SCIP_Longint* weights;

           consvars = SCIPgetVarsKnapsack(scip, cons);
           nconsvars = SCIPgetNVarsKnapsack(scip, cons);
           assert( consvars != NULL || nconsvars == 0 );

           /* copy Longint array to SCIP_Real array */
           weights = SCIPgetWeightsKnapsack(scip, cons);
           SCIP_CALL( SCIPallocBufferArray(scip, &consvals, nconsvars) );
           for( v = 0; v < nconsvars; ++v )
              consvals[v] = (SCIP_Real)weights[v];

           if( nconsvars > 0 )
           {
              SCIP_CALL( printLinearCons(scip, file, readerdata, consvars, consvals, nconsvars, nvars, transformed, &maxcoef, printbool) );
           }

           SCIPfreeBufferArray(scip, &consvals);
        }
        else if( strcmp(conshdlrname, "varbound") == 0 )
        {
           SCIP_CALL( SCIPallocBufferArray(scip, &consvars, 2) );
           SCIP_CALL( SCIPallocBufferArray(scip, &consvals, 2) );

           consvars[0] = SCIPgetVarVarbound(scip, cons);
           consvars[1] = SCIPgetVbdvarVarbound(scip, cons);

           consvals[0] = 1.0;
           consvals[1] = SCIPgetVbdcoefVarbound(scip, cons);

           SCIP_CALL( printLinearCons(scip, file, readerdata, consvars, consvals, 2, nvars, transformed, &maxcoef, printbool) );

           SCIPfreeBufferArray(scip, &consvars);
           SCIPfreeBufferArray(scip, &consvals);
        }
        else
        {
           SCIPwarningMessage(scip, "constraint handler <%s> cannot print requested format\n", conshdlrname );
           SCIPinfoMessage(scip, file, "\\ ");
           SCIP_CALL( SCIPprintCons(scip, cons, file) );
           SCIPinfoMessage(scip, file, ";\n");
        }
     }
   }

   *result = SCIP_SUCCESS;

   return SCIP_OKAY;
}