Пример #1
0
/** presolving method of constraint handler */
static
SCIP_DECL_CONSPRESOL(consPresolConjunction)
{  /*lint --e{715}*/
   SCIP_CONSDATA* consdata;
   int c;
   int i;

   assert(result != NULL);

   *result = SCIP_DIDNOTFIND;

   /* all constraints in a conjunction constraint of the global problem can be added directly to the problem and
    * removed from the conjunction constraint;
    * an unmodifiable conjunction constraint can be deleted
    */
   for( c = 0; c < nconss; ++c )
   {
      consdata = SCIPconsGetData(conss[c]);
      assert(consdata != NULL);

      /* add all inactive constraints to the global problem */
      for( i = 0; i < consdata->nconss; ++i )
      {
	 /* update check flag for sub constraints when upgrade takes place */
	 if( SCIPconsIsChecked(conss[c]) )
	 {
	    /* make sure, the constraint is checked for feasibility */
	    SCIP_CALL( SCIPsetConsChecked(scip, consdata->conss[i], TRUE) );
	 }

         /* add constraint, if it is not active yet */
         if( !SCIPconsIsActive(consdata->conss[i]) )
         {
            SCIPdebugMessage("adding constraint <%s> from add conjunction <%s>\n",
               SCIPconsGetName(consdata->conss[i]), SCIPconsGetName(conss[c]));
            SCIP_CALL( SCIPaddCons(scip, consdata->conss[i]) );
            *result = SCIP_SUCCESS;
         }
         /* release constraint because it will be removed from the conjunction constraint */
         SCIP_CALL( SCIPreleaseCons(scip, &(consdata->conss[i])) );
      }
      /* all constraints where removed, so we need to clear the array */
      consdata->nconss = 0;

      /* delete conjunction constraint, if it is unmodifiable */
      if( !SCIPconsIsModifiable(conss[c]) )
      {
         SCIP_CALL( SCIPdelCons(scip, conss[c]) );
      }
   }

   return SCIP_OKAY;
}
Пример #2
0
/** presolving method of constraint handler */
static
SCIP_DECL_CONSPRESOL(consPresolDisjunction)
{  /*lint --e{715}*/
   SCIP_CONSDATA* consdata;
   int oldndelconss;
   int c;

   assert(result != NULL);

   *result = SCIP_DIDNOTFIND;
   oldndelconss = *ndelconss;

   /* all disjunction constraints with one constraint can be replaced with that corresponding constraint */
   for( c = 0; c < nconss; ++c )
   {
      consdata = SCIPconsGetData(conss[c]);
      assert(consdata != NULL);

      if( !SCIPconsIsModifiable(conss[c]) && consdata->nconss == 1 )
      {
         /* add constraint to the problem */
         if( !SCIPconsIsActive(consdata->conss[0]) )
         {
            SCIP_CALL( SCIPaddCons(scip, consdata->conss[0]) );

            /* release constraint from the disjunction constraint */
            SCIP_CALL( SCIPreleaseCons(scip, &consdata->conss[0]) );
         }
         
         /* remove disjunction constraint */
         SCIP_CALL( SCIPdelCons(scip, conss[0]) );

         *result = SCIP_SUCCESS;
      }

      /* propagate constraint */
      SCIP_CALL( propagateCons(scip, conss[c], ndelconss) );
   }

   if( *ndelconss > oldndelconss )
      *result = SCIP_SUCCESS;
   
   return SCIP_OKAY;
}