1 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ 2 /* */ 3 /* This file is part of the program and library */ 4 /* SCIP --- Solving Constraint Integer Programs */ 5 /* */ 6 /* Copyright (c) 2002-2023 Zuse Institute Berlin (ZIB) */ 7 /* */ 8 /* Licensed under the Apache License, Version 2.0 (the "License"); */ 9 /* you may not use this file except in compliance with the License. */ 10 /* You may obtain a copy of the License at */ 11 /* */ 12 /* http://www.apache.org/licenses/LICENSE-2.0 */ 13 /* */ 14 /* Unless required by applicable law or agreed to in writing, software */ 15 /* distributed under the License is distributed on an "AS IS" BASIS, */ 16 /* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. */ 17 /* See the License for the specific language governing permissions and */ 18 /* limitations under the License. */ 19 /* */ 20 /* You should have received a copy of the Apache-2.0 license */ 21 /* along with SCIP; see the file LICENSE. If not visit scipopt.org. */ 22 /* */ 23 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ 24 25 /**@file reader_ppm.c 26 * @ingroup DEFPLUGINS_READER 27 * @brief file writer for portable pixmap file format (PPM), open with common graphic viewer programs (e.g. xview) 28 * @author Michael Winkler 29 * 30 */ 31 32 /*---+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8----+----9----+----0----+----1----+----2*/ 33 34 #include "blockmemshell/memory.h" 35 #include "scip/cons_knapsack.h" 36 #include "scip/cons_linear.h" 37 #include "scip/cons_logicor.h" 38 #include "scip/cons_setppc.h" 39 #include "scip/cons_varbound.h" 40 #include "scip/pub_cons.h" 41 #include "scip/pub_message.h" 42 #include "scip/pub_misc.h" 43 #include "scip/pub_reader.h" 44 #include "scip/pub_var.h" 45 #include "scip/reader_ppm.h" 46 #include "scip/scip_cons.h" 47 #include "scip/scip_mem.h" 48 #include "scip/scip_message.h" 49 #include "scip/scip_numerics.h" 50 #include "scip/scip_param.h" 51 #include "scip/scip_reader.h" 52 #include "scip/scip_var.h" 53 #include <string.h> 54 55 #define READER_NAME "ppmreader" 56 #define READER_DESC "file writer for portable pixmap file format (PPM), open with common graphic viewer programs (e.g. xview)" 57 #define READER_EXTENSION "ppm" 58 59 /* 60 * Data structures 61 */ 62 #define PPM_MAX_LINELEN 71 /**< the maximum length of any line is 70 + '\\0' = 71*/ 63 #define DEFAULT_PPM_RGB_LIMIT 160 64 #define DEFAULT_PPM_COEF_LIMIT 3 65 #define DEFAULT_PPM_RGB_RELATIVE TRUE 66 #define DEFAULT_PPM_RGB_ASCII TRUE 67 68 /** PPM reading data */ 69 struct SCIP_ReaderData 70 { 71 SCIP_Bool rgb_relative; 72 SCIP_Bool rgb_ascii; 73 int rgb_limit; 74 int coef_limit; 75 }; 76 77 /* 78 * Local methods (for writing) 79 */ 80 81 /** initializes the reader data */ 82 static 83 void initReaderdata( 84 SCIP_READERDATA* readerdata /**< reader data */ 85 ) 86 { 87 assert(readerdata != NULL); 88 89 readerdata->rgb_relative = DEFAULT_PPM_RGB_RELATIVE; 90 readerdata->rgb_ascii = DEFAULT_PPM_RGB_ASCII; 91 readerdata->rgb_limit = DEFAULT_PPM_RGB_LIMIT; 92 readerdata->coef_limit = DEFAULT_PPM_COEF_LIMIT; 93 } 94 95 96 /** transforms given variables, scalars, and constant to the corresponding active variables, scalars, and constant */ 97 static 98 SCIP_RETCODE getActiveVariables( 99 SCIP* scip, /**< SCIP data structure */ 100 SCIP_VAR** vars, /**< vars array to get active variables for */ 101 SCIP_Real* scalars, /**< scalars a_1, ..., a_n inrc/scip/reader_ppm.c linear sum a_1*x_1 + ... + a_n*x_n + c */ 102 int* nvars, /**< pointer to number of variables and values in vars and vals array */ 103 SCIP_Real* constant, /**< pointer to constant c in linear sum a_1*x_1 + ... + a_n*x_n + c */ 104 SCIP_Bool transformed /**< transformed constraint? */ 105 ) 106 { 107 int requiredsize; 108 int v; 109 110 assert( scip != NULL ); 111 assert( vars != NULL ); 112 assert( scalars != NULL ); 113 assert( nvars != NULL ); 114 assert( constant != NULL ); 115 116 if( transformed ) 117 { 118 SCIP_CALL( SCIPgetProbvarLinearSum(scip, vars, scalars, nvars, *nvars, constant, &requiredsize, TRUE) ); 119 120 if( requiredsize > *nvars ) 121 { 122 SCIP_CALL( SCIPreallocBufferArray(scip, &vars, requiredsize) ); 123 SCIP_CALL( SCIPreallocBufferArray(scip, &scalars, requiredsize) ); 124 125 SCIP_CALL( SCIPgetProbvarLinearSum(scip, vars, scalars, nvars, requiredsize, constant, &requiredsize, TRUE) ); 126 assert( requiredsize <= *nvars ); 127 } 128 } 129 else 130 { 131 for( v = 0; v < *nvars; ++v ) 132 { 133 SCIP_CALL( SCIPvarGetOrigvarSum(&vars[v], &scalars[v], constant) ); 134 } 135 } 136 return SCIP_OKAY; 137 } 138 139 /** clears the given line buffer */ 140 static 141 void clearLine( 142 char* linebuffer, /**< line */ 143 int* linecnt /**< number of characters in line */ 144 ) 145 { 146 assert( linebuffer != NULL ); 147 assert( linecnt != NULL ); 148 149 (*linecnt) = 0; 150 linebuffer[0] = '\0'; 151 } 152 153 /** ends the given line with '\\0' and prints it to the given file stream */ 154 static 155 void endLine( 156 SCIP* scip, /**< SCIP data structure */ 157 FILE* file, /**< output file (or NULL for standard output) */ 158 SCIP_READERDATA* readerdata, /**< information for reader */ 159 char* linebuffer, /**< line */ 160 int* linecnt /**< number of characters in line */ 161 ) 162 { 163 assert( scip != NULL ); 164 assert( linebuffer != NULL ); 165 assert( linecnt != NULL ); 166 167 if( (*linecnt) > 0 ) 168 { 169 linebuffer[(*linecnt)] = '\0'; 170 171 if(readerdata->rgb_ascii) 172 SCIPinfoMessage(scip, file, "%s", linebuffer); 173 else 174 SCIPinfoMessage(scip, file, "%s\n", linebuffer); 175 clearLine(linebuffer, linecnt); 176 } 177 } 178 179 /** appends extension to line and prints it to the give file stream if the line exceeded PPM_PRINTLEN */ 180 static 181 void appendLine( 182 SCIP* scip, /**< SCIP data structure */ 183 FILE* file, /**< output file (or NULL for standard output) */ 184 SCIP_READERDATA* readerdata, /**< information for reader */ 185 char* linebuffer, /**< line */ 186 int* linecnt, /**< number of characters in line */ 187 const char* extension /**< string to extent the line */ 188 ) 189 { 190 assert( scip != NULL ); 191 assert( linebuffer != NULL ); 192 assert( linecnt != NULL ); 193 assert( extension != NULL ); 194 195 if( *linecnt + (int)strlen(extension) > PPM_MAX_LINELEN - 1 ) 196 endLine(scip, file, readerdata, linebuffer, linecnt); 197 198 /* append extension to linebuffer */ 199 (void) strncat(linebuffer, extension, PPM_MAX_LINELEN - (unsigned int)(*linecnt) - 1); 200 (*linecnt) += (int) strlen(extension); 201 } 202 203 204 /** calculates the color value for a given coefficient */ 205 static 206 void calcColorValue( 207 SCIP* scip, /**< SCIP data structure */ 208 SCIP_READERDATA* readerdata, /**< information for reader */ 209 SCIP_Real coef, /**< coefficient to scale */ 210 int* red, /**< red part */ 211 int* green, /**< green part */ 212 int* blue, /**< blue part */ 213 SCIP_Real scale /**< maximal coefficient */ 214 ) 215 { 216 SCIP_Real coeflog; 217 218 assert(scip != NULL); 219 assert(readerdata != NULL); 220 assert(readerdata->rgb_limit >= 0); 221 assert(coef > 0); 222 223 coeflog = SCIPfloor(scip, log10(coef)); 224 225 if( !(readerdata->rgb_relative) ) 226 { 227 (*red) = 255; 228 (*blue) = readerdata->rgb_limit - (int) (unsigned short) (coef/scale * readerdata->rgb_limit); 229 (*green) = *blue; 230 } 231 else 232 { 233 if( coeflog >= 0 ) 234 { 235 (*red) = 255; 236 if( coeflog >= readerdata->coef_limit ) 237 { 238 (*blue) = 0; 239 (*green) = 0; 240 } 241 else 242 { 243 (*blue) = readerdata->rgb_limit - (int) (unsigned short) (readerdata->rgb_limit * coeflog/readerdata->coef_limit); 244 (*green) = *blue; 245 } 246 } 247 else 248 { 249 (*blue) = 255; 250 coeflog = -1.0*coeflog; 251 if( coeflog >= readerdata->coef_limit ) 252 { 253 (*red) = 0; 254 (*green) = 0; 255 } 256 else 257 { 258 (*red) = (readerdata->rgb_limit) - (int) (unsigned short) ((readerdata->rgb_limit)*coeflog/(readerdata->coef_limit)); 259 (*green) = *red; 260 } 261 } 262 } 263 } 264 265 266 /** print row in PPM format to file stream */ 267 static 268 void printRow( 269 SCIP* scip, /**< SCIP data structure */ 270 FILE* file, /**< output file (or NULL for standard output) */ 271 SCIP_READERDATA* readerdata, /**< information for reader */ 272 SCIP_VAR** vars, /**< array of constraint variables */ 273 SCIP_Real* vals, /**< array of constraint values */ 274 int nvars, /**< number of constraint variables */ 275 int ntotalvars, /**< number of variables */ 276 SCIP_Real maxcoef /**< maximal coefficient */ 277 ) 278 { 279 int v; 280 int i; 281 int j; 282 283 int red; 284 int green; 285 int blue; 286 287 char linebuffer[PPM_MAX_LINELEN]; 288 int linecnt; 289 int varindex; 290 int actvarindex; 291 int maxvarindex; 292 int indexvar = 0; 293 294 char buffer[PPM_MAX_LINELEN]; 295 const unsigned char max = (unsigned char)255; 296 char white[4]; 297 298 assert( scip != NULL ); 299 assert (nvars > 0); 300 assert (readerdata != NULL); 301 302 i = 0; 303 varindex = -1; 304 maxvarindex = 0; 305 306 (void) SCIPsnprintf(white, 4, "%c%c%c", max, max, max); 307 clearLine(linebuffer, &linecnt); 308 309 /* calculate maximum index of the variables in this constraint */ 310 for( v = 0; v < nvars; ++v ) 311 { 312 if( maxvarindex < SCIPvarGetProbindex(vars[v]) ) 313 maxvarindex = SCIPvarGetProbindex(vars[v]); 314 } 315 assert(maxvarindex < ntotalvars); 316 317 /* print coefficients */ 318 for(v = 0; v < nvars; ++v) 319 { 320 actvarindex = maxvarindex; 321 for(j = 0; j < nvars; ++j) 322 { 323 if( varindex < SCIPvarGetProbindex(vars[j]) && SCIPvarGetProbindex(vars[j]) <= actvarindex ) 324 { 325 actvarindex = SCIPvarGetProbindex(vars[j]); 326 indexvar = j; 327 } 328 } 329 varindex = actvarindex; 330 331 /* fill in white points since these variables indices do not exits in this constraint */ 332 for( ; i < varindex; ++i ) 333 { 334 if(readerdata->rgb_ascii) 335 appendLine(scip, file, readerdata, linebuffer, &linecnt, white); 336 else 337 appendLine(scip, file, readerdata, linebuffer, &linecnt, " 255 255 255 "); 338 } 339 340 calcColorValue(scip, readerdata, REALABS(vals[indexvar]), &red, &green, &blue, maxcoef); 341 if( readerdata->rgb_ascii ) 342 { 343 if( red == 35 || red == 0 ) 344 red++; 345 if( green==35 || green == 0 ) 346 green++; 347 if( blue==35 || blue == 0 ) 348 blue++; 349 (void) SCIPsnprintf(buffer, PPM_MAX_LINELEN, "%c%c%c", (unsigned char)red, (unsigned char)green, (unsigned char)blue); 350 } 351 else 352 (void) SCIPsnprintf(buffer, PPM_MAX_LINELEN, " %d %d %d ", red, green, blue); 353 354 appendLine(scip, file, readerdata, linebuffer, &linecnt, buffer); 355 i++; 356 } 357 358 /* fill in white points since these variables indices do not exits in this constraint */ 359 for( ; i < ntotalvars; ++i ) 360 { 361 if(readerdata->rgb_ascii) 362 appendLine(scip, file, readerdata, linebuffer, &linecnt, white); 363 else 364 appendLine(scip, file, readerdata, linebuffer, &linecnt, " 255 255 255 "); 365 } 366 367 endLine(scip, file, readerdata, linebuffer, &linecnt); 368 } 369 370 371 /** prints given linear constraint information in PPM format to file stream */ 372 static 373 SCIP_RETCODE printLinearCons( 374 SCIP* scip, /**< SCIP data structure */ 375 FILE* file, /**< output file (or NULL for standard output) */ 376 SCIP_READERDATA* readerdata, /**< information for reader */ 377 SCIP_VAR** vars, /**< array of variables */ 378 SCIP_Real* vals, /**< array of coefficients values (or NULL if all coefficient values are 1) */ 379 int nvars, /**< number of variables */ 380 int ncompletevars, /**< number of variables in whole problem */ 381 SCIP_Bool transformed, /**< transformed constraint? */ 382 SCIP_Real* maxcoef, /**< maximal coefficient */ 383 SCIP_Bool printbool /**< print row or calculate maximum coefficient */ 384 ) 385 { 386 int v; 387 SCIP_VAR** activevars; 388 SCIP_Real* activevals; 389 int nactivevars; 390 SCIP_Real activeconstant = 0.0; 391 392 assert( scip != NULL ); 393 assert( vars != NULL ); 394 assert( nvars > 0 ); 395 assert( readerdata != NULL ); 396 397 /* duplicate variable and value array */ 398 nactivevars = nvars; 399 SCIP_CALL( SCIPduplicateBufferArray(scip, &activevars, vars, nactivevars ) ); 400 if( vals != NULL ) 401 { 402 SCIP_CALL( SCIPduplicateBufferArray(scip, &activevals, vals, nactivevars ) ); 403 } 404 else 405 { 406 SCIP_CALL( SCIPallocBufferArray(scip, &activevals, nactivevars) ); 407 408 for( v = 0; v < nactivevars; ++v ) 409 activevals[v] = 1.0; 410 } 411 412 /* retransform given variables to active variables */ 413 SCIP_CALL( getActiveVariables(scip, activevars, activevals, &nactivevars, &activeconstant, transformed) ); 414 415 if( ! readerdata->rgb_relative ) 416 { 417 if( ! printbool ) 418 { 419 for(v = 0; v < nactivevars; ++v) 420 { 421 if( REALABS(activevals[v]) > *maxcoef) 422 *maxcoef = REALABS(activevals[v]); 423 } 424 } 425 else 426 { 427 assert (*maxcoef > 0); 428 /* print constraint */ 429 printRow(scip, file, readerdata, activevars, activevals, nactivevars, ncompletevars, *maxcoef); 430 } 431 } 432 else 433 { 434 /* print constraint */ 435 printRow(scip, file, readerdata, activevars, activevals, nactivevars, ncompletevars, *maxcoef); 436 } 437 438 /* free buffer arrays */ 439 SCIPfreeBufferArray(scip, &activevars); 440 SCIPfreeBufferArray(scip, &activevals); 441 442 return SCIP_OKAY; 443 } 444 445 446 /* 447 * Callback methods of reader 448 */ 449 450 /** copy method for reader plugins (called when SCIP copies plugins) */ 451 static 452 SCIP_DECL_READERCOPY(readerCopyPpm) 453 { /*lint --e{715}*/ 454 assert(scip != NULL); 455 assert(reader != NULL); 456 assert(strcmp(SCIPreaderGetName(reader), READER_NAME) == 0); 457 458 /* call inclusion method of reader */ 459 SCIP_CALL( SCIPincludeReaderPpm(scip) ); 460 461 return SCIP_OKAY; 462 } 463 464 /** destructor of reader to free user data (called when SCIP is exiting) */ 465 static 466 SCIP_DECL_READERFREE(readerFreePpm) 467 { 468 SCIP_READERDATA* readerdata; 469 470 assert(strcmp(SCIPreaderGetName(reader), READER_NAME) == 0); 471 readerdata = SCIPreaderGetData(reader); 472 assert(readerdata != NULL); 473 SCIPfreeBlockMemory(scip, &readerdata); 474 475 return SCIP_OKAY; 476 } 477 478 479 /** problem writing method of reader */ 480 static 481 SCIP_DECL_READERWRITE(readerWritePpm) 482 { /*lint --e{715}*/ 483 SCIP_READERDATA* readerdata; 484 485 assert(strcmp(SCIPreaderGetName(reader), READER_NAME) == 0); 486 readerdata = SCIPreaderGetData(reader); 487 assert(readerdata != NULL); 488 489 SCIP_CALL( SCIPwritePpm(scip, file, name, readerdata, transformed, vars, nvars, conss, nconss, result) ); 490 491 return SCIP_OKAY; 492 } 493 494 /* 495 * reader specific interface methods 496 */ 497 498 /** includes the ppm file reader in SCIP */ 499 SCIP_RETCODE SCIPincludeReaderPpm( 500 SCIP* scip /**< SCIP data structure */ 501 ) 502 { 503 SCIP_READERDATA* readerdata; 504 SCIP_READER* reader; 505 506 /* create ppm reader data */ 507 SCIP_CALL( SCIPallocBlockMemory(scip, &readerdata) ); 508 initReaderdata(readerdata); 509 510 /* include reader */ 511 SCIP_CALL( SCIPincludeReaderBasic(scip, &reader, READER_NAME, READER_DESC, READER_EXTENSION, readerdata) ); 512 513 assert(reader != NULL); 514 515 /* set non fundamental callbacks via setter functions */ 516 SCIP_CALL( SCIPsetReaderCopy(scip, reader, readerCopyPpm) ); 517 SCIP_CALL( SCIPsetReaderFree(scip, reader, readerFreePpm) ); 518 SCIP_CALL( SCIPsetReaderWrite(scip, reader, readerWritePpm) ); 519 520 /* add ppm reader parameters */ 521 SCIP_CALL( SCIPaddBoolParam(scip, 522 "reading/ppmreader/rgbrelativ", "should the coloring values be relativ or absolute", 523 &readerdata->rgb_relative, FALSE, DEFAULT_PPM_RGB_RELATIVE, NULL, NULL) ); 524 SCIP_CALL( SCIPaddBoolParam(scip, 525 "reading/ppmreader/rgbascii", "should the output format be binary(P6) (otherwise plain(P3) format)", 526 &readerdata->rgb_ascii, FALSE, DEFAULT_PPM_RGB_ASCII, NULL, NULL) ); 527 SCIP_CALL( SCIPaddIntParam(scip, 528 "reading/ppmreader/coefficientlimit", 529 "splitting coefficients in this number of intervals", 530 &readerdata->coef_limit, FALSE, DEFAULT_PPM_COEF_LIMIT, 3, 16, NULL, NULL) ); 531 SCIP_CALL( SCIPaddIntParam(scip, 532 "reading/ppmreader/rgblimit", 533 "maximal color value", 534 &readerdata->rgb_limit, FALSE, DEFAULT_PPM_RGB_LIMIT, 0, 255, NULL, NULL) ); 535 536 return SCIP_OKAY; 537 } 538 539 540 /** writes problem to file */ 541 SCIP_RETCODE SCIPwritePpm( 542 SCIP* scip, /**< SCIP data structure */ 543 FILE* file, /**< output file, or NULL if standard output should be used */ 544 const char* name, /**< problem name */ 545 SCIP_READERDATA* readerdata, /**< information for reader */ 546 SCIP_Bool transformed, /**< TRUE iff problem is the transformed problem */ 547 SCIP_VAR** vars, /**< array with active variables ordered binary, integer, implicit, continuous */ 548 int nvars, /**< number of active variables in the problem */ 549 SCIP_CONS** conss, /**< array with constraints of the problem */ 550 int nconss, /**< number of constraints in the problem */ 551 SCIP_RESULT* result /**< pointer to store the result of the file writing call */ 552 ) 553 { /*lint --e{715}*/ 554 int c; 555 int v; 556 int i; 557 558 int linecnt; 559 char linebuffer[PPM_MAX_LINELEN]; 560 561 SCIP_CONSHDLR* conshdlr; 562 const char* conshdlrname; 563 SCIP_CONS* cons; 564 565 SCIP_VAR** consvars; 566 SCIP_Real* consvals; 567 int nconsvars; 568 int i_max = 1; 569 SCIP_Real maxcoef = 0; 570 SCIP_Bool printbool = FALSE; 571 572 assert( scip != NULL ); 573 assert(readerdata != NULL); 574 assert(vars != NULL); /* for lint */ 575 576 /* print statistics as comment to file */ 577 if(readerdata->rgb_ascii) 578 SCIPinfoMessage(scip, file, "P6\n"); 579 else 580 SCIPinfoMessage(scip, file, "P3\n"); 581 SCIPinfoMessage(scip, file, "# %s\n", name); 582 SCIPinfoMessage(scip, file, "%d %d\n", nvars, nconss); 583 SCIPinfoMessage(scip, file, "255\n"); 584 585 clearLine(linebuffer, &linecnt); 586 587 if( ! readerdata->rgb_relative ) 588 i_max = 2; 589 590 for(i = 0; i < i_max; ++i) 591 { 592 if( i ) 593 { 594 printbool = TRUE; 595 SCIPdebugMsgPrint(scip, "Maximal coefficient = %g\n", maxcoef); 596 } 597 598 for(c = 0; c < nconss; ++c) 599 { 600 cons = conss[c]; 601 assert( cons != NULL); 602 603 /* in case the transformed is written only constraint are posted which are enabled in the current node */ 604 assert(!transformed || SCIPconsIsEnabled(cons)); 605 606 conshdlr = SCIPconsGetHdlr(cons); 607 assert( conshdlr != NULL ); 608 609 conshdlrname = SCIPconshdlrGetName(conshdlr); 610 assert( transformed == SCIPconsIsTransformed(cons) ); 611 612 if( strcmp(conshdlrname, "linear") == 0 ) 613 { 614 consvars = SCIPgetVarsLinear(scip, cons); 615 nconsvars = SCIPgetNVarsLinear(scip, cons); 616 assert( consvars != NULL || nconsvars == 0 ); 617 618 if( nconsvars > 0 ) 619 { 620 SCIP_CALL( printLinearCons(scip, file, readerdata, consvars, SCIPgetValsLinear(scip, cons), 621 nconsvars, nvars, transformed, &maxcoef, printbool) ); 622 } 623 } 624 else if( strcmp(conshdlrname, "setppc") == 0 ) 625 { 626 consvars = SCIPgetVarsSetppc(scip, cons); 627 nconsvars = SCIPgetNVarsSetppc(scip, cons); 628 assert( consvars != NULL || nconsvars == 0 ); 629 630 if( nconsvars > 0 ) 631 { 632 SCIP_CALL( printLinearCons(scip, file, readerdata, consvars, NULL, 633 nconsvars, nvars, transformed, &maxcoef, printbool) ); 634 } 635 } 636 else if( strcmp(conshdlrname, "logicor") == 0 ) 637 { 638 consvars = SCIPgetVarsLogicor(scip, cons); 639 nconsvars = SCIPgetNVarsLogicor(scip, cons); 640 assert( consvars != NULL || nconsvars == 0 ); 641 642 if( nconsvars > 0 ) 643 { 644 SCIP_CALL( printLinearCons(scip, file, readerdata, consvars, NULL, 645 nconsvars, nvars, transformed, &maxcoef, printbool) ); 646 } 647 } 648 else if( strcmp(conshdlrname, "knapsack") == 0 ) 649 { 650 SCIP_Longint* weights; 651 652 consvars = SCIPgetVarsKnapsack(scip, cons); 653 nconsvars = SCIPgetNVarsKnapsack(scip, cons); 654 assert( consvars != NULL || nconsvars == 0 ); 655 656 /* copy Longint array to SCIP_Real array */ 657 weights = SCIPgetWeightsKnapsack(scip, cons); 658 SCIP_CALL( SCIPallocBufferArray(scip, &consvals, nconsvars) ); 659 for( v = 0; v < nconsvars; ++v ) 660 consvals[v] = (SCIP_Real)weights[v]; 661 662 if( nconsvars > 0 ) 663 { 664 SCIP_CALL( printLinearCons(scip, file, readerdata, consvars, consvals, nconsvars, nvars, transformed, &maxcoef, printbool) ); 665 } 666 667 SCIPfreeBufferArray(scip, &consvals); 668 } 669 else if( strcmp(conshdlrname, "varbound") == 0 ) 670 { 671 SCIP_CALL( SCIPallocBufferArray(scip, &consvars, 2) ); 672 SCIP_CALL( SCIPallocBufferArray(scip, &consvals, 2) ); 673 674 consvars[0] = SCIPgetVarVarbound(scip, cons); 675 consvars[1] = SCIPgetVbdvarVarbound(scip, cons); 676 677 consvals[0] = 1.0; 678 consvals[1] = SCIPgetVbdcoefVarbound(scip, cons); 679 680 SCIP_CALL( printLinearCons(scip, file, readerdata, consvars, consvals, 2, nvars, transformed, &maxcoef, printbool) ); 681 682 SCIPfreeBufferArray(scip, &consvars); 683 SCIPfreeBufferArray(scip, &consvals); 684 } 685 else 686 { 687 SCIPwarningMessage(scip, "constraint handler <%s> cannot print requested format\n", conshdlrname ); 688 SCIPinfoMessage(scip, file, "\\ "); 689 SCIP_CALL( SCIPprintCons(scip, cons, file) ); 690 SCIPinfoMessage(scip, file, ";\n"); 691 } 692 } 693 } 694 695 *result = SCIP_SUCCESS; 696 697 return SCIP_OKAY; /*lint !e438*/ 698 } 699