[SCIP] how can I output my best solution using SCIPgetBestSol() to a file?
Ambros Gleixner
gleixner at zib.de
Thu Sep 17 23:48:26 CEST 2020
Dear Melvin,
I am afraid this is too unspecific for us to help from the SCIP side.
Best,
Ambros
Am 14.09.20 um 09:36 schrieb Melvin Shih:
> Dear Naga and SCIP menbers,
>
> I am thankful for the help.
> I have tried FILE* fp, and VS 2019 forced me to use fopen_s,
> then SCIPprintSol() accepted the fp.
> However, an Exception Unhandled occurs.
> The screen picture is attached.
>
> Actually, I need to print my problem and solution into a file to check
> details, no matter using SCIP_FILE* or FILE*.
> The file is also needed for further applications.
> cmd screen cannot satisfy the needs.
>
> Many thanks for your help.
> Look forward to further response from you or SCIP menbers.
>
> Sincerely,
>
> Melvin Shih
>
> 16.png
>
>
> Naga Venkata Chaitanya Gudapati - nagavenkata.gudapati at studio.unibo.it
> <mailto:nagavenkata.gudapati at studio.unibo.it>
> <nagavenkata.gudapati at studio.unibo.it
> <mailto:nagavenkata.gudapati at studio.unibo.it>> 於 2020年9月14日 週一 下
> 午3:14寫道:
>
> 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 <mailto:scip-bounces at zib.de>> on
> behalf of Naga Venkata Chaitanya Gudapati -
> nagavenkata.gudapati at studio.unibo.it
> <mailto:nagavenkata.gudapati at studio.unibo.it>
> <nagavenkata.gudapati at studio.unibo.it
> <mailto:nagavenkata.gudapati at studio.unibo.it>>
> Sent: Monday, September 14, 2020 7:56 AM
> To: Melvin Shih; scip at zib.de <mailto: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 <mailto:scip-bounces at zib.de>> on
> behalf of Melvin Shih <melvinshih at gmail.com
> <mailto:melvinshih at gmail.com>>
> Sent: Sunday, September 13, 2020 8:09 PM
> To: scip at zib.de <mailto: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 <mailto:Scip at zib.de>
> https://listserv.zib.de/mailman/listinfo/scip
>
>
> _______________________________________________
> Scip mailing list
> Scip at zib.de
> https://listserv.zib.de/mailman/listinfo/scip
>
--
Ambros Gleixner, Research Group Mathematical Optimization Methods at
Zuse Institute Berlin, http://www.zib.de/gleixner
More information about the Scip
mailing list