crown  1.0.0
src/integrated2allocation.cpp
Go to the documentation of this file.
00001 /*
00002  Copyright 2015 Nicolas Melot
00003 
00004  This file is part of Crown.
00005 
00006  Crown is free software: you can redistribute it and/or modify
00007  it under the terms of the GNU General Public License as published by
00008  the Free Software Foundation, either version 3 of the License, or
00009  (at your option) any later version.
00010 
00011  Crown is distributed in the hope that it will be useful,
00012  but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
00014  GNU General Public License for more details.
00015 
00016  You should have received a copy of the GNU General Public License
00017  along with Crown. If not, see <http://www.gnu.org/licenses/>.
00018 
00019 */
00020 
00021 
00022 #include <iostream>
00023 #include <cstdlib>
00024 #include <fstream>
00025 #include <string>
00026 #include <boost/regex.hpp>
00027 #include <iomanip>
00028 
00029 #include <pelib/AmplInput.hpp>
00030 #include <pelib/AmplOutput.hpp>
00031 
00032 #include <pelib/AmplInputData.hpp>
00033 #include <pelib/AmplInputScalar.hpp>
00034 #include <pelib/AmplInputVector.hpp>
00035 #include <pelib/AmplInputMatrix.hpp>
00036 
00037 #include <pelib/AmplOutputScalar.hpp>
00038 #include <pelib/AmplOutputVector.hpp>
00039 #include <pelib/AmplOutputMatrix.hpp>
00040 
00041 using namespace pelib;
00042 
00043 Algebra
00044 parse(AlgebraParser &parser, std::istream &input)
00045 {
00046         Algebra rec;
00047         
00048         try {
00049                 rec = parser.parse(input);
00050         } catch(ParseException &e)
00051         {
00052                 std::cerr << e.what() << std::endl;
00053         }
00054 
00055         return rec;
00056 }
00057 
00058 int
00059 main(int argc, char **argv)
00060 {
00061         AmplOutput input(AmplOutput::floatHandlers());
00062         AmplInput output(AmplInput::floatHandlers());
00063         Algebra rec;
00064 
00065         // Set floating point var output format to fixed at 7 digits
00066         std::cout << std::setprecision(6)                                                                                                        
00067         << std::setiosflags(std::ios::fixed)                                                                                                     
00068         << std::setiosflags(std::ios::showpoint);
00069 
00070         // Open input file
00071         std::ifstream myfile;
00072         myfile.open (argv[1], std::ios::in);
00073 
00074         // Load input file
00075         rec = parse(input, myfile);
00076 
00077         // Close input file
00078         myfile.close();
00079 
00080         const Scalar<float> *float_M = rec.find<Scalar<float> >("M");
00081         if(float_M != NULL)
00082         {
00083                 output.dump(std::cout, float_M);
00084         }
00085         const Scalar<float> *int_M = rec.find<Scalar<float> >("M");
00086         if(int_M != NULL)
00087         {
00088                 output.dump(std::cout, int_M);
00089         }
00090 
00091         //out.dump(std::cout, rec);
00092         output.dump(std::cout, rec.find<Scalar<float> >("n"));
00093         output.dump(std::cout, rec.find<Vector<int, float> >("Wi"));
00094         output.dump(std::cout, rec.find<Vector<int, float> >("wi"));
00095         output.dump(std::cout, rec.find<Vector<int, float> >("Tau"));
00096         output.dump(std::cout, rec.find<Matrix<int, int, float> >("e"));
00097 
00098 #if 0
00099         // Output one raw value in parameters b, Wi and e
00100         std::cout << rec.find<Scalar<float> >("b")->getValue() << std::endl;
00101         std::cout << rec.find<Vector<int, float> >("Wi")->getSize() << std::endl;
00102         std::cout << rec.find<Matrix<int, int, float> >("e")->getRowSize() << std::endl;
00103 
00104         // Extract, rename and output a few parameters
00105         Scalar<float> nn(rec.find<Scalar<float> >("n"));
00106         nn.setName("nn");
00107         out.dump(std::cout, &nn);
00108 
00109         Vector<int, float> yy(rec.find<Vector<int, float> >("Wi"));
00110         yy.setName("yy");
00111         out.dump(std::cout, &yy);
00112         
00113         Matrix<int, int, float> ee(rec.find<Matrix<int, int, float> >("e"));
00114         ee.setName("ee");
00115         out.dump(std::cout, &ee);
00116 #endif
00117 
00118         return EXIT_SUCCESS;
00119 }
00120