Skip to content

Commit

Permalink
Merge branch 'copy_variable_data' into 'master'
Browse files Browse the repository at this point in the history
Copy variable data

See merge request integer/scip!3375
  • Loading branch information
svigerske committed Apr 11, 2024
2 parents d51f4ac + 824634a commit 988dd4c
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 22 deletions.
1 change: 1 addition & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
Features
--------
- Added new fields in history to store ancestral pseudo cost updates, used in the pseudo costs branching rule to compute discounted pseudo costs.
- Copy variable data pointer if no copy routine was supplied.

Performance improvements
------------------------
Expand Down
10 changes: 5 additions & 5 deletions src/scip/type_var.h
Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,8 @@ typedef struct SCIP_VarData SCIP_VARDATA; /**< user variable data */
* Because the original variable and the user data of the original variable should not be
* modified during the solving process, a transformed variable is created as a copy of
* the original variable. If the user variable data is never modified during the solving
* process anyways, it is enough to simple copy the user data's pointer. This is the
* default implementation, which is used when a NULL is given as VARTRANS method.
* process anyways, it is enough to simply copy the user data's pointer. This is the
* default implementation, which is used when NULL is given as the VARTRANS method.
* If the user data may be modified during the solving process (e.g. during preprocessing),
* the VARTRANS method must be given and has to copy the user variable data to a different
* memory location.
Expand Down Expand Up @@ -166,13 +166,13 @@ typedef struct SCIP_VarData SCIP_VARDATA; /**< user variable data */
/** copies variable data of source SCIP variable for the target SCIP variable
*
* This method should copy the variable data of the source SCIP and create a target variable data for target
* variable. This callback is optimal. If the copying process was successful the target variable gets this variable
* data assigned. In case the result pointer is set to SCIP_DIDNOTRUN the target variable will have no variable data at
* variable. This callback is optional. If the copying process was successful, the target variable gets this variable
* data assigned. In case the result pointer is set to SCIP_DIDNOTRUN, the target variable will have no variable data at
* all.
*
* The variable map and the constraint map can be used via the function SCIPgetVarCopy() and SCIPgetConsCopy(),
* respectively, to get for certain variables and constraints of the source SCIP the counter parts in the target
* SCIP. You should be very carefully in using these two methods since they could lead to infinity loop.
* SCIP. You should be very careful in using these two methods since they could lead to infinite loop.
*
* input:
* - scip : target SCIP data structure
Expand Down
42 changes: 25 additions & 17 deletions src/scip/var.c
Original file line number Diff line number Diff line change
Expand Up @@ -2219,28 +2219,36 @@ SCIP_RETCODE SCIPvarCopy(
SCIP_CALL( SCIPhashmapInsert(varmap, sourcevar, *var) );

/* in case there exists variable data and the variable data copy callback, try to copy variable data */
if( sourcevar->vardata != NULL && sourcevar->varcopy != NULL )
if( sourcevar->vardata != NULL )
{
SCIP_CALL( sourcevar->varcopy(set->scip, sourcescip, sourcevar, sourcevar->vardata,
varmap, consmap, (*var), &targetdata, &result) );

/* evaluate result */
if( result != SCIP_DIDNOTRUN && result != SCIP_SUCCESS )
if( sourcevar->varcopy != NULL )
{
SCIPerrorMessage("variable data copying method returned invalid result <%d>\n", result);
return SCIP_INVALIDRESULT;
}
SCIP_CALL( sourcevar->varcopy(set->scip, sourcescip, sourcevar, sourcevar->vardata,
varmap, consmap, (*var), &targetdata, &result) );

/* evaluate result */
if( result != SCIP_DIDNOTRUN && result != SCIP_SUCCESS )
{
SCIPerrorMessage("variable data copying method returned invalid result <%d>\n", result);
return SCIP_INVALIDRESULT;
}

assert(targetdata == NULL || result == SCIP_SUCCESS);
assert(targetdata == NULL || result == SCIP_SUCCESS);

/* if copying was successful, add the created variable data to the variable as well as all callback methods */
if( result == SCIP_SUCCESS )
/* if copying was successful, add the created variable data to the variable as well as all callback methods */
if( result == SCIP_SUCCESS )
{
(*var)->varcopy = sourcevar->varcopy;
(*var)->vardelorig = sourcevar->vardelorig;
(*var)->vartrans = sourcevar->vartrans;
(*var)->vardeltrans = sourcevar->vardeltrans;
(*var)->vardata = targetdata;
}
}
else
{
(*var)->varcopy = sourcevar->varcopy;
(*var)->vardelorig = sourcevar->vardelorig;
(*var)->vartrans = sourcevar->vartrans;
(*var)->vardeltrans = sourcevar->vardeltrans;
(*var)->vardata = targetdata;
/* if there is no copy callback, just copy data pointers */
(*var)->vardata = sourcevar->vardata;
}
}

Expand Down

0 comments on commit 988dd4c

Please sign in to comment.