79#if _POSIX_C_SOURCE < 2
85 stream = popen(
"python",
"w");
92 fputs(
"import numpy as np\n"
94 "import matplotlib.pyplot as plt\n",
97 fputs(
"fig, ax = plt.subplots()\n"
109 fprintf(stream,
"patches.append(matplotlib.patches.Circle((%g, %g), %g))\n",
115 fputs(
"colors = 100*np.random.rand(len(patches))\n"
116 "p = matplotlib.collections.PatchCollection(patches, alpha=0.4)\n"
117 "p.set_array(np.array(colors))\n"
118 "ax.add_collection(p)\n",
127 fputs(
"plt.gca().set_aspect(1)\n", stream);
128 fputs(
"plt.show()\n", stream);
141#if _POSIX_C_SOURCE < 2
150 stream = popen(
"gnuplot -p",
"w");
157 fputs(
"unset xtics\n"
160 "set size ratio 1\n",
166 fprintf(stream,
"set xrange [0:%.2f]\n",
MAX(wval, hval));
167 fprintf(stream,
"set yrange [0:%.2f]\n",
MAX(wval, hval));
168 fprintf(stream,
"set object rectangle from 0,0 to %.2f,%.2f\n", wval, hval);
174 fputs(
"plot '-' with circles notitle\n", stream);
181 fprintf(stream,
"%g %g %g\n",
186 fputs(
"e\n", stream);
217 scalex = (dispwidth-3) / wval;
218 scaley = scalex / 2.0;
226 memset(picture,
' ', width * height);
227 picture[width*height] =
'\0';
230 memset(picture,
'*', width-1);
231 memset(picture + (height-1) * width,
'*', width-1);
232 for(
i = 0;
i < height; ++
i )
234 picture[
i*width] =
'*';
235 picture[
i*width + width-2] =
'*';
236 picture[
i*width + width-1] =
'\n';
254 for(
phi = 0.0;
phi < 6.283 ;
phi += 0.01 )
267 picture[ycoord * width + xcoord] =
'a' +
i;
274 picture[width/2-8+
i] =
'*';
328 eventExecDispsol,
NULL) );
498 SCIP_CALL(
SCIPcreateConsQuadraticNonlinear(
scip, &cons,
"area", 1, &
a, &minusone, 1, &
w, &
h, &one, -
SCIPinfinity(
scip),
521 SCIP_Real quadcoefs[6] = {1.0, 1.0, -2.0, 1.0, 1.0, -2.0};
532 lincoefs[0] = -
SQR(
r[
i] +
r[j]);
534 lincoefs[1] = -
SQR(
r[
i] +
r[j]);
646 for(
i = 1;
i < argc; ++
i )
648 if( strcmp(argv[
i],
"--help") == 0 )
650 printf(
"usage: %s [--help] [-w <width>] [-h <height>]", argv[0]);
651#if _POSIX_C_SOURCE >= 2
652 printf(
" [-g] [-m]");
654 puts(
" { <radius> }");
655 puts(
" --help shows this help and exits");
656 puts(
" -w <width> fix rectangle width to given value");
657 puts(
" -h <height> fix rectangle height to given value");
658#if _POSIX_C_SOURCE >= 2
659 puts(
" -g show final solution with gnuplot");
660 puts(
" -m show final solution with matplotlib");
662 puts(
"If no radii are given, then 5 circles with radii 0.25, 0.25, 0.4, 0.7, and 0.1 used.");
663 puts(
"If both width and height are fixed, then the number of circles that fit into the rectangle is maximized.");
668#if _POSIX_C_SOURCE >= 2
669 if( strcmp(argv[
i],
"-g") == 0 )
675 if( strcmp(argv[
i],
"-m") == 0 )
682 if( strcmp(argv[
i],
"-w") == 0 )
686 fprintf(stderr,
"ERROR: Missing argument for -w.\n");
690 fixwidth = strtod(argv[
i+1], &endptr);
691 if( *endptr !=
'\0' )
693 fprintf(stderr,
"ERROR: Could not parse argument %s into a number.\n", argv[
i+1]);
701 if( strcmp(argv[
i],
"-h") == 0 )
705 fprintf(stderr,
"ERROR: Missing argument for -h.\n");
709 fixheight = strtod(argv[
i+1], &endptr);
710 if( *endptr !=
'\0' )
712 fprintf(stderr,
"ERROR: Could not parse argument %s into a number.\n", argv[
i+1]);
727 if( *endptr ==
'\0' && endptr != argv[
i] &&
r[
ncircles] > 0.0 )
733 fprintf(stderr,
"ERROR: Unknown option %s.\n", argv[
i]);
749 retcode =
runPacking(fixwidth, fixheight, dognuplot, domatplotlib);
static SCIP_RETCODE runPacking(SCIP_Real fixwidth, SCIP_Real fixheight, SCIP_Bool dognuplot, SCIP_Bool domatplotlib)
static SCIP_RETCODE visualizeSolutionAscii(SCIP *scip, SCIP_SOL *sol)
int main(int argc, char **argv)
static SCIP_RETCODE setupProblem(SCIP *scip, SCIP_Real fixwidth, SCIP_Real fixheight)
static SCIP_RETCODE includeEventHdlrDispsol(SCIP *scip)
static void visualizeSolutionGnuplot(SCIP *scip, SCIP_SOL *sol)
static void visualizeSolutionMatplotlib(SCIP *scip, SCIP_SOL *sol)
#define SCIP_ALLOC_ABORT(x)
SCIP_RETCODE SCIPaddCoefLinear(SCIP *scip, SCIP_CONS *cons, SCIP_VAR *var, SCIP_Real val)
SCIP_RETCODE SCIPcreateConsBasicLinear(SCIP *scip, SCIP_CONS **cons, const char *name, int nvars, SCIP_VAR **vars, SCIP_Real *vals, SCIP_Real lhs, SCIP_Real rhs)
SCIP_RETCODE SCIPcreateConsQuadraticNonlinear(SCIP *scip, SCIP_CONS **cons, const char *name, int nlinvars, SCIP_VAR **linvars, SCIP_Real *lincoefs, int nquadterms, SCIP_VAR **quadvars1, SCIP_VAR **quadvars2, SCIP_Real *quadcoefs, SCIP_Real lhs, SCIP_Real rhs, SCIP_Bool initial, SCIP_Bool separate, SCIP_Bool enforce, SCIP_Bool check, SCIP_Bool propagate, SCIP_Bool local, SCIP_Bool modifiable, SCIP_Bool dynamic, SCIP_Bool removable)
SCIP_RETCODE SCIPfree(SCIP **scip)
SCIP_RETCODE SCIPcreate(SCIP **scip)
SCIP_RETCODE SCIPaddVar(SCIP *scip, SCIP_VAR *var)
SCIP_RETCODE SCIPaddCons(SCIP *scip, SCIP_CONS *cons)
SCIP_RETCODE SCIPsetObjsense(SCIP *scip, SCIP_OBJSENSE objsense)
SCIP_RETCODE SCIPcreateProbBasic(SCIP *scip, const char *name)
void SCIPinfoMessage(SCIP *scip, FILE *file, const char *formatstr,...)
void SCIPprintError(SCIP_RETCODE retcode)
SCIP_RETCODE SCIPgetIntParam(SCIP *scip, const char *name, int *value)
SCIP_RETCODE SCIPsetRealParam(SCIP *scip, const char *name, SCIP_Real value)
SCIP_RETCODE SCIPreleaseCons(SCIP *scip, SCIP_CONS **cons)
SCIP_RETCODE SCIPincludeEventhdlrBasic(SCIP *scip, SCIP_EVENTHDLR **eventhdlrptr, const char *name, const char *desc, SCIP_DECL_EVENTEXEC((*eventexec)), SCIP_EVENTHDLRDATA *eventhdlrdata)
SCIP_RETCODE SCIPsetEventhdlrExit(SCIP *scip, SCIP_EVENTHDLR *eventhdlr,)
SCIP_RETCODE SCIPsetEventhdlrInit(SCIP *scip, SCIP_EVENTHDLR *eventhdlr,)
SCIP_EVENTTYPE SCIPeventGetType(SCIP_EVENT *event)
SCIP_SOL * SCIPeventGetSol(SCIP_EVENT *event)
SCIP_RETCODE SCIPcatchEvent(SCIP *scip, SCIP_EVENTTYPE eventtype, SCIP_EVENTHDLR *eventhdlr, SCIP_EVENTDATA *eventdata, int *filterpos)
SCIP_RETCODE SCIPdropEvent(SCIP *scip, SCIP_EVENTTYPE eventtype, SCIP_EVENTHDLR *eventhdlr, SCIP_EVENTDATA *eventdata, int filterpos)
#define SCIPallocMemoryArray(scip, ptr, num)
#define SCIPallocBufferArray(scip, ptr, num)
#define SCIPfreeBufferArray(scip, ptr)
#define SCIPfreeMemoryArray(scip, ptr)
SCIP_SOL * SCIPgetBestSol(SCIP *scip)
SCIP_RETCODE SCIPprintSol(SCIP *scip, SCIP_SOL *sol, FILE *file, SCIP_Bool printzeros)
int SCIPgetNSols(SCIP *scip)
SCIP_Real SCIPgetSolOrigObj(SCIP *scip, SCIP_SOL *sol)
SCIP_Real SCIPgetSolVal(SCIP *scip, SCIP_SOL *sol, SCIP_VAR *var)
SCIP_RETCODE SCIPsolve(SCIP *scip)
SCIP_RETCODE SCIPprintOrigProblem(SCIP *scip, FILE *file, const char *extension, SCIP_Bool genericnames)
SCIP_Real SCIPinfinity(SCIP *scip)
SCIP_Real SCIPround(SCIP *scip, SCIP_Real val)
SCIP_Real SCIPceil(SCIP *scip, SCIP_Real val)
SCIP_Bool SCIPisLT(SCIP *scip, SCIP_Real val1, SCIP_Real val2)
SCIP_RETCODE SCIPreleaseVar(SCIP *scip, SCIP_VAR **var)
SCIP_RETCODE SCIPfixVar(SCIP *scip, SCIP_VAR *var, SCIP_Real fixedval, SCIP_Bool *infeasible, SCIP_Bool *fixed)
SCIP_RETCODE SCIPcreateVarBasic(SCIP *scip, SCIP_VAR **var, const char *name, SCIP_Real lb, SCIP_Real ub, SCIP_Real obj, SCIP_VARTYPE vartype)
int SCIPsnprintf(char *t, int len, const char *s,...)
assert(minobj< SCIPgetCutoffbound(scip))
#define BMSreallocMemoryArray(ptr, num)
#define BMSallocMemoryArray(ptr, num)
SCIP_RETCODE SCIPincludeDefaultPlugins(SCIP *scip)
static SCIP_Real phi(SCIP *scip, SCIP_Real val, SCIP_Real lb, SCIP_Real ub)
struct SCIP_Cons SCIP_CONS
struct SCIP_Eventhdlr SCIP_EVENTHDLR
#define SCIP_DECL_EVENTEXIT(x)
#define SCIP_DECL_EVENTEXEC(x)
#define SCIP_DECL_EVENTINIT(x)
#define SCIP_EVENTTYPE_BESTSOLFOUND
enum SCIP_Retcode SCIP_RETCODE
@ SCIP_VARTYPE_CONTINUOUS