Skip to content
This repository has been archived by the owner on Mar 5, 2019. It is now read-only.

Commit

Permalink
add CSIPinterrupt()
Browse files Browse the repository at this point in the history
  • Loading branch information
rschwarz committed Aug 22, 2016
1 parent 7d22568 commit d95e449
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 0 deletions.
3 changes: 3 additions & 0 deletions include/csip.h
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,9 @@ CSIP_RETCODE CSIPsetSenseMaximize(CSIP_MODEL *model);
// Solve the model.
CSIP_RETCODE CSIPsolve(CSIP_MODEL *model);

// Interrupt the solving process.
CSIP_RETCODE CSIPinterrupt(CSIP_MODEL *model);

// Copy the values of all variables in the best known solution into
// the output array. The user is responsible for memory allocation.
CSIP_RETCODE CSIPgetVarValues(CSIP_MODEL *model, double *output);
Expand Down
5 changes: 5 additions & 0 deletions src/csip.c
Original file line number Diff line number Diff line change
Expand Up @@ -553,6 +553,11 @@ CSIP_RETCODE CSIPsolve(CSIP_MODEL *model)
return CSIP_RETCODE_OK;
}

CSIP_RETCODE CSIPinterrupt(CSIP_MODEL *model)
{
SCIP_in_CSIP(SCIPinterruptSolve(model->scip));
return CSIP_RETCODE_OK;
}

CSIP_STATUS CSIPgetStatus(CSIP_MODEL *model)
{
Expand Down
32 changes: 32 additions & 0 deletions test/test.c
Original file line number Diff line number Diff line change
Expand Up @@ -368,6 +368,37 @@ static void test_lazy2()
CHECK(CSIPfreeModel(m));
}

CSIP_RETCODE lazycb_interrupt(CSIP_MODEL *m, CSIP_CBDATA *cb, void *userdata)
{
CHECK(CSIPinterrupt(m));
return CSIP_RETCODE_OK;
}

static void test_lazy_interrupt()
{
/*
find x
s.t. x >= 1.5, integer
solution is interrupted
*/

CSIP_MODEL *m;

CHECK(CSIPcreateModel(&m));
CHECK(CSIPsetParameter(m, "display/verblevel", 2));
CHECK(CSIPaddVar(m, 1.5, INFINITY, CSIP_VARTYPE_INTEGER, NULL));

int fractional = 1;
CHECK(CSIPaddLazyCallback(m, lazycb_interrupt, fractional, NULL));

CHECK(CSIPsolve(m));

int solvestatus = CSIPgetStatus(m);
mu_assert_int("Wrong status!", solvestatus, CSIP_STATUS_USERLIMIT);

CHECK(CSIPfreeModel(m));
}

static void test_objsense()
{
// min/max x
Expand Down Expand Up @@ -788,6 +819,7 @@ int main(int argc, char **argv)
mu_run_test(test_socp);
mu_run_test(test_lazy);
mu_run_test(test_lazy2);
mu_run_test(test_lazy_interrupt);
mu_run_test(test_objsense);
mu_run_test(test_sos1);
mu_run_test(test_sos2);
Expand Down

0 comments on commit d95e449

Please sign in to comment.