MeshKit
1.0
|
00001 // IASolverTool.hpp 00002 // Interval Assignment for Meshkit 00003 // common solver utility functions for checking and computing data 00004 00005 #ifndef MESHKIT_IA_IASOLVERTOOL_HP 00006 #define MESHKIT_IA_IASOLVERTOOL_HP 00007 00008 #include <cstddef> 00009 #include <utility> // for pair 00010 00011 namespace MeshKit { 00012 00013 class IAData; 00014 class IASolution; 00015 00016 class IASolverTool 00017 { 00018 // no data or inheritance, except debugging flags 00019 public: 00021 IASolverTool() 00022 : iaData(NULL), iaSolution(NULL), debuggingTool(false) 00023 {} 00024 IASolverTool( const IAData *ia_data, IASolution *ia_solution, bool debugging_set = false) 00025 : iaData(ia_data), iaSolution(ia_solution), debuggingTool( debugging_set ) 00026 {} 00027 IASolverTool(const bool debugging_set) 00028 : iaData(NULL), iaSolution(NULL), debuggingTool(debugging_set) 00029 {} 00030 00032 virtual ~IASolverTool(); 00033 00034 // member get/set 00035 const IAData *ia_data() const {return iaData;} 00036 IASolution *ia_solution() const {return iaSolution;} 00037 void ia_data(const IAData *set_data) {iaData = set_data;} 00038 void ia_solution(IASolution *set_solution) {iaSolution = set_solution;} 00039 virtual void set_debug(const bool debugging_set) {debuggingTool = debugging_set;} 00040 00041 00042 // data checking 00043 // data interogation 00044 00045 // true if a solution has been defined, and it is the right size to match the data 00046 bool valid_solution() const; 00047 00048 // true if x is within standardized epsilon of an integer 00049 bool is_integer(const double x) const; 00050 // also rounds x to nearest integer (up or down) 00051 bool is_integer(const double x, int &x_int) const; 00052 bool is_integer(const double x, double &x_int_double) const; 00053 00054 // data computation 00055 bool is_even(double y) const; 00056 bool is_even(double y, int &y_even) const; 00057 // see also even_constraint 00058 00059 // compute the value of the ith constraint 00060 // the even one rounds nearly-integer x to integer x 00061 double equal_value(int i) const; 00062 double even_value(int i) const; 00063 00064 void even_floor_ceil(double s, double &s_floor, double &s_ceil) const; 00065 void int_floor_ceil(double x, double &x_floor, double &x_ceil) const; 00066 00067 // first is true if constraint is satisfied 00068 // second contains the value of the constraint 00069 // ith constraint 00070 std::pair< bool, double> equal_constraint(const int i, 00071 const bool print_me=false, 00072 const bool print_unsatisfied=false ) const; 00073 std::pair< bool, double> even_constraint(const int i, 00074 const bool print_me=false, 00075 const bool print_unsatisfied=false ) const; 00076 // all constraints satisfied? 00077 bool equal_constraints( const bool print_me=false, 00078 const bool print_unsatisfied=false ) const; 00079 bool even_constraints( const bool print_me=false, 00080 const bool print_unsatisfied=false ) const; 00081 // all types 00082 bool all_constraints( const bool print_me=false, 00083 const bool print_unsatisfied=false ) const; 00084 00085 // data printing for debugging 00086 void print_solution() const; 00087 void print_problem() const; 00088 void print( const bool do_print_solution, const bool do_print_nonint, 00089 const bool do_print_equal_constraints, const bool do_print_nonequal, 00090 const bool do_print_even_constraints, const bool do_print_noneven 00091 ) const; 00092 void print() const 00093 { print (true, true, true, true, true, true); } 00094 void print_violations() const 00095 { print(false, true, false, true, false, true); } 00096 00097 protected: 00098 00099 // problem definition and solution 00100 const IAData *iaData; 00101 IASolution *iaSolution; 00102 00103 // debugging 00104 bool debuggingTool; 00105 00106 }; 00107 00108 } // namespace MeshKit 00109 #endif