[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 09:14:22 CEST 2020
Looks like I jumped the gun a little and just saw your full email and the attempt at trying to print the solution to a file. I am not sure about the inner workings of SCIP_FILE * but a normal C-style FILE * seems to be working okay.
________________________________________
From: Scip <scip-bounces at zib.de> on behalf of Naga Venkata Chaitanya Gudapati - nagavenkata.gudapati at studio.unibo.it <nagavenkata.gudapati at studio.unibo.it>
Sent: Monday, September 14, 2020 7:56 AM
To: Melvin Shih; scip at zib.de
Subject: Re: [SCIP] how can I output my best solution using SCIPgetBestSol() to a file?
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);
..........
_______________________________________________
Scip mailing list
Scip at zib.de
https://listserv.zib.de/mailman/listinfo/scip
More information about the Scip
mailing list