QSapecNG
 All Classes Functions Enumerations Properties
metacircuit.h
00001 /*
00002     SapecNG - Next Generation Symbolic Analysis Program for Electric Circuit
00003     Copyright (C) 2009, Michele Caini
00004 
00005     This program is free software: you can redistribute it and/or modify
00006     it under the terms of the GNU General Public License as published by
00007     the Free Software Foundation, either version 3 of the License, or
00008     (at your option) any later version.
00009 
00010     This program is distributed in the hope that it will be useful,
00011     but WITHOUT ANY WARRANTY; without even the implied warranty of
00012     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013     GNU General Public License for more details.
00014 
00015     You should have received a copy of the GNU General Public License
00016     along with this program.  If not, see <http://www.gnu.org/licenses/>.
00017 */
00018 
00019 
00020 #ifndef METACIRCUIT_H
00021 #define METACIRCUIT_H
00022 
00023 
00024 #include "model/circuit.h"
00025 #include <list>
00026 #include <map>
00027 
00028 
00029 namespace sapecng
00030 {
00031 
00032 
00033 
00034 namespace detail
00035 {
00036 
00037 
00038 struct basic_checker
00039 {
00040 
00041 bool operator()(const std::pair< double, std::list<std::string> >& e) const
00042   { return (e.first == 0); }
00043 
00044 };
00045 
00046 
00047 struct degree_checker
00048 {
00049 
00050 bool operator()(const std::pair< int, std::list<
00051     std::pair< double, std::list<std::string> > > >& e) const
00052   { return (e.second.size() == 0); }
00053 
00054 };
00055 
00056 
00057 }
00058 
00059 
00060 
00061 class metacircuit
00062 {
00063 
00064 public:
00065   typedef
00066   std::pair< double, std::list<std::string> >
00067   basic_expression;
00068 
00069   typedef
00070   std::list< basic_expression >
00071   degree_expression;
00072 
00073   typedef
00074   std::map< int, degree_expression >
00075   expression;
00076 
00077   static std::string as_string(const expression& e);
00078   void operator()(const circuit& circ);
00079 
00080   inline std::pair<metacircuit::expression, metacircuit::expression>
00081     raw() const { return raw_; }
00082   inline std::pair<metacircuit::expression, metacircuit::expression>
00083     digit() const { return digit_; }
00084   inline std::pair<metacircuit::expression, metacircuit::expression>
00085     mixed() const { return mixed_; }
00086 
00087 private:
00088   void append(int deg, expression& e, const basic_expression& be);
00089   void simplify(std::pair<expression, expression>& p);
00090 
00091   void compress(expression& e);
00092   bool group_minus(const expression& e);
00093   void toggle_minus(expression& e);
00094   bool has_candidate(const expression& e, const std::string& c);
00095   void remove_candidate(expression& e, const std::string& c);
00096   double find_div(const expression& e);
00097   void normalize(expression& e, double div);
00098 
00099   static std::string stringify(double x);
00100   static std::string as_string(const degree_expression& e);
00101   static std::string as_string(const basic_expression& e);
00102 
00103   int get_sign(
00104       size_t vertices,
00105       const Graph& graph,
00106       std::vector< circuit::edge_descriptor > order,
00107       std::vector<bool> inL
00108     );
00109 
00110 private:
00111   std::pair<metacircuit::expression, metacircuit::expression> raw_;
00112   std::pair<metacircuit::expression, metacircuit::expression> digit_;
00113   std::pair<metacircuit::expression, metacircuit::expression> mixed_;
00114 
00115 };
00116 
00117 
00118 
00119 }
00120 
00121 
00122 #endif // METACIRCUIT_H
 All Classes Functions Enumerations Properties