[SCIP] how can I output my best solution using SCIPgetBestSol() to a file?

Naga Venkata Chaitanya Gudapati - nagavenkata.gudapati@studio.unibo.it nagavenkata.gudapati at studio.unibo.it
Mon Sep 14 07:56:08 CEST 2020


Hi!

If I understood your question correctly,

You need to use

SCIP_RETCODE SCIPprintSol(SCIP * scip,  SCIP_SOL * sol,  FILE * file, SCIP_Bool printzeros )    ;

In c++, if you just want to print the solution to the console with all the 0 variable printed too, you can use:
 SCIP_SOL* sol = nullptr;
 sol = SCIPgetBestSol(scip);
 SCIP_CALL(SCIPprintSol (scip, sol, nullptr, 1));

If you want to write to a file with 0s,
SCIP_SOL* sol = nullptr;
sol = SCIPgetBestSol(scip);
FILE *fp;
fp = fopen("MYSOL.TXT", "w+");
SCIP_CALL(SCIPprintSol (scip, sol, fp, 1));
fclose(fp);

I also have a Minimum Working Example if you need. I hope this is what you are looking for. I hope other SCIP members will chime in if I am wrong.

Regards,
Naga



________________________________________
From: Scip <scip-bounces at zib.de> on behalf of Melvin Shih <melvinshih at gmail.com>
Sent: Sunday, September 13, 2020 8:09 PM
To: scip at zib.de
Subject: [SCIP] how can I output my best solution using SCIPgetBestSol() to     a file?

Dear SCIP members,

I have tried functions of fstream and SCIP_FILE to open a file for SCIPgetBestSol(), and they do not work.
Is there any example to define a file for  SCIPgetBestSol() or is there another way to do so using C++?

Sincerely,

Melvin shih


Here are my codes:
.............
// fstream file;
// file.open("Reader.txt", ios::out | ios::trunc);       //not work

SCIP_FILE* schedulingfile;
char filename[255];
(void)SCIPsnprintf(filename, 255, "Sintex.txt");
schedulingfile = SCIPfopen(filename, "r");
if (schedulingfile == NULL)
{
SCIPerrorMessage("cannot open file <%s> for reading\n", filename);
SCIPprintSysError(filename);
return SCIP_NOFILE;
}
if (SCIPgetNSols(scip) > 0)
{
SCIPinfoMessage(scip, NULL, "\nSolution:\n");
SCIP_CALL(SCIPprintSol(scip, SCIPgetBestSol(scip), schedulingfile, FALSE));   //SCIP_FILE is not accepted
}
SCIPfclose(schedulingfile);
..........




More information about the Scip mailing list