本文整理汇总了C++中SCIPallocBufferArray函数的典型用法代码示例。如果您正苦于以下问题:C++ SCIPallocBufferArray函数的具体用法?C++ SCIPallocBufferArray怎么用?C++ SCIPallocBufferArray使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了SCIPallocBufferArray函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: JNISCIPCONSLINEAR
/** creates and captures a linear constraint
* in its most basic version, i. e., all constraint flags are set to their basic value as explained for the
* method SCIPcreateConsLinear(); all flags can be set via SCIPsetConsFLAGNAME-methods in scip.h
*
* @see SCIPcreateConsLinear() for information about the basic constraint flag configuration
*
* @note the constraint gets captured, hence at one point you have to release it using the method SCIPreleaseCons()
*/
JNIEXPORT
jlong JNISCIPCONSLINEAR(createConsBasicLinear)(
JNIEnv* env, /**< JNI environment variable */
jobject jobj, /**< JNI class pointer */
jlong jscip, /**< SCIP data structure */
jstring jname, /**< name of constraint */
jint jnvars, /**< number of nonzeros in the constraint */
jlongArray jvars, /**< array with variables of constraint entries */
jdoubleArray jvals, /**< array with coefficients of constraint entries */
jdouble jlhs, /**< left hand side of constraint */
jdouble jrhs /**< right hand side of constraint */
)
{
SCIP* scip;
SCIP_CONS* cons;
const char* name;
int nvars;
/* convert JNI pointer into C pointer */
scip = (SCIP*) (size_t) jscip;
assert(scip != NULL);
/* convert JNI string into C const char* */
name = (*env)->GetStringUTFChars(env, jname, NULL);
if( name == NULL )
SCIPABORT();
/* create linear constraint with zero variables */
JNISCIP_CALL( SCIPcreateConsBasicLinear(scip, &cons, name, 0, NULL, NULL, (SCIP_Real) jlhs, (SCIP_Real) jrhs) );
/* convert JNI integer into integer */
nvars = (int)jnvars;
if( nvars > 0 )
{
jlong* vars;
jdouble* vals;
int v;
JNISCIP_CALL( SCIPallocBufferArray(scip, &vars, nvars) );
JNISCIP_CALL( SCIPallocBufferArray(scip, &vals, nvars) );
(*env)->GetLongArrayRegion(env, jvars, 0, nvars, vars);
(*env)->GetDoubleArrayRegion(env, jvals, 0, nvars, vals);
for( v = 0; v < nvars; ++v )
{
JNISCIP_CALL( SCIPaddCoefLinear(scip, cons, (SCIP_VAR*)(size_t)vars[v], (SCIP_Real)vals[v]));
}
SCIPfreeBufferArray(scip, &vals);
SCIPfreeBufferArray(scip, &vars);
}
/* relase string object */
(*env)->ReleaseStringUTFChars(env, jname, name);
return (jlong)(size_t)cons;
}
示例2: JNISCIPREADERPIP
/** writes problem to file */
JNIEXPORT
jint JNISCIPREADERPIP(writePip)(
JNIEnv* env, /**< JNI environment variable */
jobject jobj, /**< JNI class pointer */
jlong jscip, /**< SCIP data structure */
jlong jfile, /**< output file, or NULL if standard output should be used */
jstring jname, /**< problem name */
jboolean jtransformed, /**< TRUE iff problem is the transformed problem */
jint jobjsense, /**< objective sense */
jdouble jobjscale, /**< scalar applied to objective function; external objective value is
* extobj = objsense * objscale * (intobj + objoffset) */
jdouble jobjoffset, /**< objective offset from bound shifting and fixing */
jlongArray jvars, /**< array with active variables ordered binary, integer, implicit, continuous */
jint jnvars, /**< number of mutable variables in the problem */
jint jnbinvars, /**< number of binary variables */
jint jnintvars, /**< number of general integer variables */
jint jnimplvars, /**< number of implicit integer variables */
jint jncontvars, /**< number of continuous variables */
jlongArray jconss, /**< array with constraints of the problem */
jint jnconss /**< number of constraints in the problem */
)
{
SCIP* scip;
const char* name;
SCIP_VAR** vars;
SCIP_CONS** conss;
SCIP_RESULT result;
jboolean iscopy;
/* convert JNI pointer into C pointer */
scip = (SCIP*) (size_t) jscip;
assert(scip != NULL);
JNISCIP_CALL( SCIPallocBufferArray(scip, &vars, (int)jnvars) );
JNISCIP_CALL( SCIPallocBufferArray(scip, &conss, (int)jnconss) );
(*env)->GetLongArrayRegion(env, jvars, 0, jnvars, (jlong*)(*vars));
(*env)->GetLongArrayRegion(env, jconss, 0, jnconss, (jlong*)(*conss));
/* convert JNI string into C const char* */
name = (*env)->GetStringUTFChars(env, jname, &iscopy);
if( name == NULL )
SCIPABORT();
assert(iscopy);
JNISCIP_CALL( SCIPwritePip(scip, (FILE*)(size_t) jfile, name, (SCIP_Bool)jtransformed, (SCIP_OBJSENSE)jobjsense, (SCIP_Real)jobjscale, (SCIP_Real)jobjoffset, vars, (int)jnvars, (int)jnbinvars, (int)jnintvars, (jint)jnimplvars, (int)jncontvars, conss, (int)jnconss, &result) );
SCIPfreeBufferArray(scip, &vars);
SCIPfreeBufferArray(scip, &conss);
(*env)->ReleaseStringUTFChars(env, jname, name);
return (jint) result;
}
示例3: createNewSol
/** creates a new solution for the original problem by copying the solution of the subproblem */
static
SCIP_RETCODE createNewSol(
SCIP* scip, /**< original SCIP data structure */
SCIP_HEUR* heur, /**< the current heuristic */
SCIP_SOL* sol, /**< solution of the subproblem */
SCIP_Bool* success /**< used to store whether new solution was found or not */
)
{
SCIP_VAR** vars; /* the original problem's variables */
int nvars; /* the original problem's number of variables */
SCIP_Real* solvals; /* solution values of the subproblem */
SCIP_SOL* newsol; /* solution to be created for the original problem */
assert(scip != NULL);
/* get variables' data */
SCIP_CALL( SCIPgetVarsData(scip, &vars, &nvars, NULL, NULL, NULL, NULL) );
SCIP_CALL( SCIPallocBufferArray(scip, &solvals, nvars) );
/* copy the solution */
SCIP_CALL( SCIPgetSolVals(scip, sol, nvars, vars, solvals) );
/* create new solution for the original problem */
SCIP_CALL( SCIPcreateSol(scip, &newsol, heur) );
SCIP_CALL( SCIPsetSolVals(scip, newsol, nvars, vars, solvals) );
/* try to add new solution to scip and free it immediately */
SCIP_CALL( SCIPtrySolFree(scip, &newsol, FALSE, TRUE, TRUE, TRUE, success) );
SCIPfreeBufferArray(scip, &solvals);
return SCIP_OKAY;
}
示例4: selectBranchingVertex
static
SCIP_RETCODE selectBranchingVertex(
SCIP* scip, /**< original SCIP data structure */
int* vertex /**< the vertex to branch on */
)
{
SCIP_PROBDATA* probdata;
SCIP_VAR** edgevars;
GRAPH* g;
SCIP_Real maxflow;
SCIP_Real* inflow;
int a;
int k;
int nnodes;
int branchvert;
/* get problem data */
probdata = SCIPgetProbData(scip);
assert(probdata != NULL);
/* get graph */
g = SCIPprobdataGetGraph(probdata);
assert(g != NULL);
/* LP has not been solved */
if( !SCIPhasCurrentNodeLP(scip) || SCIPgetLPSolstat(scip) != SCIP_LPSOLSTAT_OPTIMAL )
{
*vertex = UNKNOWN;
return SCIP_OKAY;
}
edgevars = SCIPprobdataGetEdgeVars(scip);
assert(edgevars != NULL);
nnodes = g->knots;
SCIP_CALL( SCIPallocBufferArray(scip, &inflow, nnodes) );
branchvert = UNKNOWN;
maxflow = 1.0;
for( k = 0; k < nnodes; k++ )
{
inflow[k] = 0.0;
for( a = g->inpbeg[k]; a != EAT_LAST; a = g->ieat[a] )
inflow[k] += SCIPvarGetLPSol(edgevars[a]);
if( !Is_term(g->term[k]) && SCIPisLT(scip, inflow[k], 1.0) && SCIPisLT(scip, fabs(inflow[k] - 0.5), maxflow) )
{
branchvert = k;
maxflow = fabs(inflow[k] - 0.5);
SCIPdebugMessage("new maxflow %f on vertex %d \n", inflow[k], branchvert );
}
}
SCIPdebugMessage("maxflow %f on vertex %d, term? %d \n", maxflow, branchvert, Is_term(g->term[branchvert]) );
(*vertex) = branchvert;
SCIPfreeBufferArray(scip, &inflow);
return SCIP_OKAY;
}
示例5: JNISCIPREADERCCG
/** writes problem to file */
JNIEXPORT
jint JNISCIPREADERCCG(writeCcg)(
JNIEnv* env, /**< JNI environment variable */
jobject jobj, /**< JNI class pointer */
jlong jscip, /**< SCIP data structure */
jlong jfile, /**< output file, or NULL if standard output should be used */
jstring jname, /**< problem name */
jboolean jtransformed, /**< TRUE iff problem is the transformed problem */
jlongArray jvars, /**< array with active variables ordered binary, integer, implicit, continuous */
jint jnvars, /**< number of mutable variables in the problem */
jlongArray jconss, /**< array with constraints of the problem */
jint jnconss /**< number of constraints in the problem */
)
{
SCIP* scip;
const char* name;
SCIP_VAR** vars;
SCIP_CONS** conss;
SCIP_RESULT result;
jboolean iscopy;
/* convert JNI pointer into C pointer */
scip = (SCIP*) (size_t) jscip;
assert(scip != NULL);
JNISCIP_CALL( SCIPallocBufferArray(scip, &vars, (int)jnvars) );
JNISCIP_CALL( SCIPallocBufferArray(scip, &conss, (int)jnconss) );
(*env)->GetLongArrayRegion(env, jvars, 0, jnvars, (jlong*)(*vars));
(*env)->GetLongArrayRegion(env, jconss, 0, jnconss, (jlong*)(*conss));
/* convert JNI string into C const char* */
name = (*env)->GetStringUTFChars(env, jname, &iscopy);
if( name == NULL )
SCIPABORT();
assert(iscopy);
JNISCIP_CALL( SCIPwriteCcg(scip, (FILE*)(size_t)jfile, name, (SCIP_Bool)jtransformed, vars, (int)jnvars, conss, (int)jnconss, &result) );
SCIPfreeBufferArray(scip, &vars);
SCIPfreeBufferArray(scip, &conss);
(*env)->ReleaseStringUTFChars(env, jname, name);
return (jint) result;
}
示例6: JNISCIPCONSINDICATOR
/** creates and captures an indicator constraint with given linear constraint and slack variable
* in its most basic version, i. e., all constraint flags are set to their basic value as explained for the
* method SCIPcreateConsIndicator(); all flags can be set via SCIPsetConsFLAGNAME-methods in scip.h
*
* @note @a binvar is checked to be binary only later. This enables a change of the type in
* procedures reading an instance.
*
* @note we assume that @a slackvar actually appears in @a lincons and we also assume that it takes
* the role of a slack variable!
*
* @note the constraint gets captured, hence at one point you have to release it using the method SCIPreleaseCons()
*
* @see SCIPcreateConsIndicatorLinCons() for information about the basic constraint flag configuration
*
* @note the constraint gets captured, hence at one point you have to release it using the method SCIPreleaseCons()
*/
JNIEXPORT
jlong JNISCIPCONSINDICATOR(createConsBasicIndicator)(
JNIEnv* env, /**< JNI environment variable */
jobject jobj, /**< JNI class pointer */
jlong jscip, /**< SCIP data structure */
jstring jname, /**< name of constraint */
jlong jbinvar, /**< binary indicator variable (or NULL) */
jint nvars, /**< number of variables in the inequality */
jlongArray jvars, /**< array with variables of inequality (or NULL) */
jdoubleArray jvals, /**< values of variables in inequality (or NULL) */
jdouble rhs /**< rhs of the inequality */
)
{
SCIP* scip;
SCIP_CONS* cons;
const char* name;
SCIP_VAR* binvar;
SCIP_VAR** vars;
SCIP_Real* vals;
/* convert JNI pointer into C pointer */
scip = (SCIP*) (size_t) jscip;
assert(scip != NULL);
/* convert JNI string into C const char* */
name = (*env)->GetStringUTFChars(env, jname, NULL);
if( name == NULL )
SCIPABORT();
/* convert JNI pointer into C pointer */
binvar = (SCIP_VAR*) (size_t) jbinvar;
JNISCIP_CALL( SCIPallocBufferArray(scip, &vars, nvars) );
JNISCIP_CALL( SCIPallocBufferArray(scip, &vals, nvars) );
(*env)->GetLongArrayRegion(env, jvars, 0, nvars, (jlong*)(*vars));
(*env)->GetDoubleArrayRegion(env, jvals, 0, nvars, (jdouble*)vals);
JNISCIP_CALL( SCIPcreateConsBasicIndicator(scip, &cons, name, binvar, (int)nvars, vars, vals, (SCIP_Real)rhs) );
SCIPfreeBufferArray(scip, &vals);
SCIPfreeBufferArray(scip, &vars);
(*env)->ReleaseStringUTFChars(env, jname, name);
return (jlong)(size_t)cons;
}
示例7: createRows
/** creates the rows of the subproblem */
static
SCIP_RETCODE createRows(
SCIP* scip, /**< original SCIP data structure */
SCIP* subscip, /**< SCIP data structure for the subproblem */
SCIP_VAR** subvars /**< the variables of the subproblem */
)
{
SCIP_ROW** rows; /* original scip rows */
SCIP_CONS* cons; /* new constraint */
SCIP_VAR** consvars; /* new constraint's variables */
SCIP_COL** cols; /* original row's columns */
SCIP_Real constant; /* constant added to the row */
SCIP_Real lhs; /* left hand side of the row */
SCIP_Real rhs; /* left right side of the row */
SCIP_Real* vals; /* variables' coefficient values of the row */
int nrows;
int nnonz;
int i;
int j;
/* get the rows and their number */
SCIP_CALL( SCIPgetLPRowsData(scip, &rows, &nrows) );
/* copy all rows to linear constraints */
for( i = 0; i < nrows; i++ )
{
/* ignore rows that are only locally valid */
if( SCIProwIsLocal(rows[i]) )
continue;
/* get the row's data */
constant = SCIProwGetConstant(rows[i]);
lhs = SCIProwGetLhs(rows[i]) - constant;
rhs = SCIProwGetRhs(rows[i]) - constant;
vals = SCIProwGetVals(rows[i]);
nnonz = SCIProwGetNNonz(rows[i]);
cols = SCIProwGetCols(rows[i]);
assert(lhs <= rhs);
/* allocate memory array to be filled with the corresponding subproblem variables */
SCIP_CALL( SCIPallocBufferArray(scip, &consvars, nnonz) );
for( j = 0; j < nnonz; j++ )
consvars[j] = subvars[SCIPvarGetProbindex(SCIPcolGetVar(cols[j]))];
/* create a new linear constraint and add it to the subproblem */
SCIP_CALL( SCIPcreateConsLinear(subscip, &cons, SCIProwGetName(rows[i]), nnonz, consvars, vals, lhs, rhs,
TRUE, TRUE, TRUE, TRUE, TRUE, FALSE, FALSE, TRUE, TRUE, FALSE) );
SCIP_CALL( SCIPaddCons(subscip, cons) );
SCIP_CALL( SCIPreleaseCons(subscip, &cons) );
/* free temporary memory */
SCIPfreeBufferArray(scip, &consvars);
}
return SCIP_OKAY;
}
示例8: getJobs
/** parese job informations */
static
SCIP_RETCODE getJobs(
SCIP* scip, /**< SCIP data structure */
int lineno, /**< current line number of input file */
char* linestr, /**< current line */
STATE* state, /**< pointer to current reading state */
SCIP_RCPSPDATA* rcpspdata /**< pointer to resources constrained project scheduling data */
)
{
char jobname[SCIP_MAXSTRLEN];
int value;
int jobid;
int r;
assert(linestr != NULL);
assert(state != NULL);
/* skip lines which are not of interest */
if ( (!strncmp(linestr, "REQUESTS", 4) ) || ( !strncmp(linestr, "jobnr", 3) ) || ( !strncmp(linestr, "-", 1) ) )
{
*state = JOBS;
return SCIP_OKAY;
}
/* parse job id */
SCIPstrToIntValue(linestr, &value, &linestr);
jobid = value - 1;
/* construct job name */
(void)SCIPsnprintf(jobname, SCIP_MAXSTRLEN, "%d" , jobid) ;
/* copy job name */
SCIP_CALL( SCIPduplicateBufferArray(scip, &rcpspdata->jobnames[jobid], jobname, strlen(jobname) + 1) );
/* skip next value */
SCIPstrToIntValue(linestr, &value, &linestr);
/* parse duration */
SCIPstrToIntValue(linestr, &value, &linestr);
rcpspdata->durations[jobid] = value;
SCIP_CALL( SCIPallocBufferArray(scip, &rcpspdata->demands[jobid], rcpspdata->nresources) );
/* parse demands */
for( r = 0; r < rcpspdata->nresources; ++r )
{
SCIPstrToIntValue(linestr, &value, &linestr);
rcpspdata->demands[jobid][r] = value;
}
/* check if we paresed the last job */
if(jobid == rcpspdata->njobs - 1)
*state = NEXT;
return SCIP_OKAY;
}
示例9: initGraph
/** initialize graph */
static
SCIP_RETCODE initGraph(
SCIP* scip, /**< SCIP data structure */
SparseGraph* G, /**< graph to free */
unsigned int nNodes, /**< number of nodes */
unsigned int initSize /**< initial size of lists */
)
{
unsigned int i;
G->n = nNodes;
G->m = 0;
SCIP_CALL( SCIPallocBufferArray(scip, &G->deg, (int) nNodes) );
SCIP_CALL( SCIPallocBufferArray(scip, &G->size, (int) nNodes) );
SCIP_CALL( SCIPallocBufferArray(scip, &G->A, (int) nNodes) );
SCIP_CALL( SCIPallocBufferArray(scip, &G->W, (int) nNodes) );
for( i = 0; i < nNodes; ++i )
{
G->deg[i] = 0;
G->size[i] = initSize;
SCIP_CALL( SCIPallocBufferArray(scip, &(G->A[i]), (int) initSize) ); /*lint !e866 */
SCIP_CALL( SCIPallocBufferArray(scip, &(G->W[i]), (int) initSize) ); /*lint !e866 */
G->A[i][0] = -1;
}
return SCIP_OKAY;
}
示例10: getNResources
/** parese number of resources */
static
SCIP_RETCODE getNResources(
SCIP* scip, /**< SCIP data structure */
int lineno, /**< current line number of input file */
char* linestr, /**< current line */
STATE* state, /**< pointer to current reading state */
SCIP_RCPSPDATA* rcpspdata /**< pointer to resources constrained project scheduling data */
)
{
SCIP_Real nresources;
char* endptr;
char* number;
assert(linestr != NULL);
assert(state != NULL);
if( strncmp(linestr, "RESOURCES", 4) == 0 )
return SCIP_OKAY;
/* truncate the line via ':' and ignore the first part */
(void)SCIPstrtok(linestr, ":", &endptr);
number = SCIPstrtok(NULL, ":", &endptr);
if( !SCIPstrToRealValue(number, &nresources, &endptr) )
{
parseError(scip, lineno, "expexted number of resources", linestr, state);
return SCIP_OKAY;
}
rcpspdata->nresources = (int)(nresources + 0.5);
SCIP_CALL( SCIPallocBufferArray(scip, &rcpspdata->capacities, nresources) );
SCIP_CALL( SCIPallocBufferArray(scip, &rcpspdata->resourcenames, nresources) );
*state = NEXT;
return SCIP_OKAY;
}
示例11: SCIP_DECL_SEPAEXECLP
/** LP solution separation method of separator */
static
SCIP_DECL_SEPAEXECLP(sepaExeclpImpliedbounds)
{ /*lint --e{715}*/
SCIP_VAR** vars;
SCIP_VAR** fracvars;
SCIP_Real* solvals;
SCIP_Real* fracvals;
SCIP_Bool cutoff;
int nvars;
int nbinvars;
int nfracs;
int ncuts;
assert(sepa != NULL);
assert(scip != NULL);
*result = SCIP_DIDNOTRUN;
/* gets active problem variables */
SCIP_CALL( SCIPgetVarsData(scip, &vars, &nvars, &nbinvars, NULL, NULL, NULL) );
if( nbinvars == 0 )
return SCIP_OKAY;
/* get fractional problem variables */
/* todo try out also separating fractional implicit integer variables */
SCIP_CALL( SCIPgetLPBranchCands(scip, &fracvars, &fracvals, NULL, &nfracs, NULL, NULL) );
if( nfracs == 0 )
return SCIP_OKAY;
/* get solution values for all variables */
SCIP_CALL( SCIPallocBufferArray(scip, &solvals, nvars) );
SCIP_CALL( SCIPgetVarSols(scip, nvars, vars, solvals) );
/* call the cut separation */
SCIP_CALL( separateCuts(scip, sepa, NULL, solvals, fracvars, fracvals, nfracs, &cutoff, &ncuts) );
/* adjust result code */
if ( cutoff )
*result = SCIP_CUTOFF;
else if ( ncuts > 0 )
*result = SCIP_SEPARATED;
else
*result = SCIP_DIDNOTFIND;
/* free temporary memory */
SCIPfreeBufferArray(scip, &solvals);
return SCIP_OKAY;
}
示例12: SCIP_DECL_CONSCOPY
/** constraint copying method of constraint handler */
static
SCIP_DECL_CONSCOPY(consCopyConjuction)
{ /*lint --e{715}*/
SCIP_CONSDATA* sourcedata;
SCIP_CONS** sourceconss;
SCIP_CONS** conss;
int nconss;
int c;
sourcedata = SCIPconsGetData(sourcecons);
assert(sourcedata != NULL);
nconss = sourcedata->nconss;
if( nconss == 0 && !SCIPconsIsModifiable(sourcecons) )
{
*valid = TRUE;
return SCIP_OKAY;
}
SCIP_CALL( SCIPallocBufferArray(scip, &conss, nconss) );
sourceconss = sourcedata->conss;
/* copy each constraint one by one */
for( c = 0; c < nconss && (*valid); ++c )
{
SCIP_CALL( SCIPgetConsCopy(sourcescip, scip, sourceconss[c], &conss[c], sourceconshdlr,
varmap, consmap, SCIPconsGetName(sourceconss[c]),
SCIPconsIsInitial(sourceconss[c]), SCIPconsIsSeparated(sourceconss[c]), SCIPconsIsEnforced(sourceconss[c]),
SCIPconsIsChecked(sourceconss[c]), SCIPconsIsPropagated(sourceconss[c]),
SCIPconsIsLocal(sourceconss[c]), SCIPconsIsModifiable(sourceconss[c]),
SCIPconsIsDynamic(sourceconss[c]), SCIPconsIsRemovable(sourceconss[c]), SCIPconsIsStickingAtNode(sourceconss[c]),
global, valid) );
assert(!(*valid) || conss[c] != NULL);
}
if( *valid )
{
SCIP_CALL( SCIPcreateConsDisjunction(scip, cons, name, nconss, conss,
initial, enforce, check, local, modifiable, dynamic) );
}
SCIPfreeBufferArray(scip, &conss);
return SCIP_OKAY;
}
示例13: createNewSol
/** creates a new solution for the original problem by copying the solution of the subproblem */
static
SCIP_RETCODE createNewSol(
SCIP* scip, /**< original SCIP data structure */
SCIP* subscip, /**< SCIP structure of the subproblem */
SCIP_VAR** subvars, /**< the variables of the subproblem */
SCIP_HEUR* heur, /**< crossover heuristic structure */
SCIP_SOL* subsol, /**< solution of the subproblem */
int* solindex, /**< index of the solution */
SCIP_Bool* success /**< used to store whether new solution was found or not */
)
{
SCIP_VAR** vars; /* the original problem's variables */
int nvars;
SCIP_SOL* newsol; /* solution to be created for the original problem */
SCIP_Real* subsolvals; /* solution values of the subproblem */
assert(scip != NULL);
assert(subscip != NULL);
assert(subvars != NULL);
assert(subsol != NULL);
/* get variables' data */
SCIP_CALL( SCIPgetVarsData(scip, &vars, &nvars, NULL, NULL, NULL, NULL) );
/* sub-SCIP may have more variables than the number of active (transformed) variables in the main SCIP
* since constraint copying may have required the copy of variables that are fixed in the main SCIP
*/
assert(nvars <= SCIPgetNOrigVars(subscip));
SCIP_CALL( SCIPallocBufferArray(scip, &subsolvals, nvars) );
/* copy the solution */
SCIP_CALL( SCIPgetSolVals(subscip, subsol, nvars, subvars, subsolvals) );
/* create new solution for the original problem */
SCIP_CALL( SCIPcreateSol(scip, &newsol, heur) );
SCIP_CALL( SCIPsetSolVals(scip, newsol, nvars, vars, subsolvals) );
*solindex = SCIPsolGetIndex(newsol);
/* try to add new solution to scip and free it immediately */
SCIP_CALL( SCIPtrySolFree(scip, &newsol, FALSE, TRUE, TRUE, TRUE, success) );
SCIPfreeBufferArray(scip, &subsolvals);
return SCIP_OKAY;
}
示例14: handleLinearCons
/** handle given linear constraint information */
static
SCIP_RETCODE handleLinearCons(
SCIP* scip, /**< SCIP data structure */
SCIP_VAR** vars, /**< array of variables */
SCIP_Real* vals, /**< array of coefficients values (or NULL if all coefficient values are 1) */
int nvars, /**< number of variables */
SCIP_Bool transformed, /**< transformed constraint? */
SparseGraph* G /**< graph */
)
{
int v;
SCIP_VAR** activevars;
SCIP_Real* activevals;
int nactivevars;
SCIP_Real activeconstant = 0.0;
assert( scip != NULL );
assert( nvars > 0 );
/* duplicate variable and value array */
nactivevars = nvars;
SCIP_CALL( SCIPduplicateBufferArray(scip, &activevars, vars, nactivevars ) );
if( vals != NULL )
SCIP_CALL( SCIPduplicateBufferArray(scip, &activevals, vals, nactivevars ) );
else
{
SCIP_CALL( SCIPallocBufferArray(scip, &activevals, nactivevars) );
for( v = 0; v < nactivevars; ++v )
activevals[v] = 1.0;
}
/* retransform given variables to active variables */
SCIP_CALL( getActiveVariables(scip, activevars, activevals, &nactivevars, &activeconstant, transformed) );
/* print constraint */
SCIP_CALL( createEdgesFromRow(scip, activevars, activevals, nactivevars, G) );
/* free buffer arrays */
SCIPfreeBufferArray(scip, &activevars);
SCIPfreeBufferArray(scip, &activevals);
return SCIP_OKAY;
}
示例15: createNewSol
/** creates a new solution for the original problem by copying the solution of the subproblem */
static
SCIP_RETCODE createNewSol(
SCIP* scip, /**< SCIP data structure of the original problem */
SCIP* subscip, /**< SCIP data structure of the subproblem */
SCIP_VAR** subvars, /**< the variables of the subproblem */
SCIP_HEUR* heur, /**< the Localbranching heuristic */
SCIP_SOL* subsol, /**< solution of the subproblem */
SCIP_Bool* success /**< pointer to store, whether new solution was found */
)
{
SCIP_VAR** vars;
int nvars;
SCIP_SOL* newsol;
SCIP_Real* subsolvals;
assert( scip != NULL );
assert( subscip != NULL );
assert( subvars != NULL );
assert( subsol != NULL );
/* copy the solution */
SCIP_CALL( SCIPgetVarsData(scip, &vars, &nvars, NULL, NULL, NULL, NULL) );
/* sub-SCIP may have more variables than the number of active (transformed) variables in the main SCIP
* since constraint copying may have required the copy of variables that are fixed in the main SCIP
*/
assert(nvars <= SCIPgetNOrigVars(subscip));
SCIP_CALL( SCIPallocBufferArray(scip, &subsolvals, nvars) );
/* copy the solution */
SCIP_CALL( SCIPgetSolVals(subscip, subsol, nvars, subvars, subsolvals) );
/* create new solution for the original problem */
SCIP_CALL( SCIPcreateSol(scip, &newsol, heur) );
SCIP_CALL( SCIPsetSolVals(scip, newsol, nvars, vars, subsolvals) );
SCIP_CALL( SCIPtrySolFree(scip, &newsol, FALSE, TRUE, TRUE, TRUE, success) );
SCIPfreeBufferArray(scip, &subsolvals);
return SCIP_OKAY;
}