1    	/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2    	/*                                                                           */
3    	/*                  This file is part of the class library                   */
4    	/*       SoPlex --- the Sequential object-oriented simPlex.                  */
5    	/*                                                                           */
6    	/*  Copyright (c) 1996-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 SoPlex; see the file LICENSE. If not email to soplex@zib.de.  */
22   	/*                                                                           */
23   	/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
24   	
25   	#include <iostream>
26   	#include <fstream>
27   	#include <string.h>
28   	#include <sstream>
29   	
30   	#include "soplex/spxdefines.h"
31   	#include "soplex/spxsolver.h"
32   	#include "soplex/spxpricer.h"
33   	#include "soplex/spxratiotester.h"
34   	#include "soplex/spxstarter.h"
35   	#include "soplex/slinsolver.h"
36   	#include "soplex/slufactor.h"
37   	
38   	namespace soplex
39   	{
40   	template <class R>
41   	bool SPxSolverBase<R>::writeState(
42   	   const char*    filename,
43   	   const NameSet* rowNames,
44   	   const NameSet* colNames,
45   	   const bool cpxFormat
46   	) const
47   	{
48   	
49   	   std::string ofname;
50   	   std::ofstream ofs;
51   	
52   	   // write parameter settings
53   	   ofname = std::string(filename) + ".set";
54   	   ofs.open(ofname.c_str());
55   	
56   	   if(!ofs)
57   	      return false;
58   	
59   	   ofs << "# SoPlex version " << SOPLEX_VERSION / 100
60   	       << "." << (SOPLEX_VERSION / 10) % 10
61   	       << "." << SOPLEX_VERSION % 10
62   	       << "." << SOPLEX_SUBVERSION << std::endl << std::endl;
63   	   ofs << "# run SoPlex as follows:" << std::endl;
64   	   ofs << "# bin/soplex --loadset=spxcheck.set --readbas=spxcheck.bas spxcheck.mps\n" << std::endl;
65   	   ofs << "int:representation = " << (rep() == SPxSolverBase<R>::COLUMN ? "1" : "2") << std::endl;
66   	   ofs << "int:factor_update_max = " << basis().getMaxUpdates() << std::endl;
67   	   ofs << "int:pricer = ";
68   	
69   	   if(!strcmp(pricer()->getName(), "Auto"))
70   	      ofs << " 0" << std::endl;
71   	   else if(!strcmp(pricer()->getName(), "Dantzig"))
72   	      ofs << "1" << std::endl;
73   	   else if(!strcmp(pricer()->getName(), "ParMult"))
74   	      ofs << "2" << std::endl;
75   	   else if(!strcmp(pricer()->getName(), "Devex"))
76   	      ofs << "3" << std::endl;
77   	   else if(!strcmp(pricer()->getName(), "Steep"))
78   	      ofs << "4" << std::endl;
79   	   else if(!strcmp(pricer()->getName(), "SteepEx"))
80   	      ofs << "5" << std::endl;
81   	
82   	   ofs << "int:ratiotester = ";
83   	
84   	   if(!strcmp(ratiotester()->getName(), "Default"))
85   	      ofs << "0" << std::endl;
86   	   else if(!strcmp(ratiotester()->getName(), "Harris"))
87   	      ofs << "1" << std::endl;
88   	   else if(!strcmp(ratiotester()->getName(), "Fast"))
89   	      ofs << "2" << std::endl;
90   	   else if(!strcmp(ratiotester()->getName(), "Bound Flipping"))
91   	      ofs << "3" << std::endl;
92   	
93   	   ofs << "real:feastol = " << tolerances()->floatingPointFeastol() << std::endl;
94   	   ofs << "real:opttol = " << tolerances()->floatingPointOpttol() << std::endl;
95   	   ofs << "real:epsilon_zero = " << epsilon() << std::endl;
96   	   ofs << "real:infty = " << infinity << std::endl;
97   	   ofs << "uint:random_seed = " << random.getSeed() << std::endl;
98   	   ofs.close();
99   	
100  	   // write LP
101  	   ofname = std::string(filename) + ".mps";
102  	   ofs.open(ofname.c_str());
103  	
104  	   if(!ofs)
105  	      return false;
106  	
107  	   this->writeMPS(ofs, rowNames, colNames, NULL);
108  	   ofs.close();
109  	
110  	   // write basis
111  	   ofname = std::string(filename) + ".bas";
112  	   return writeBasisFile(ofname.c_str(), rowNames, colNames, cpxFormat);
113  	}
114  	
115  	} // namespace soplex
116