00001 // Definitions for handling return codes and messages of local optimization IEs -*- C++ -*- 00002 00003 // $Id: termreason.h 347 2008-02-06 15:20:01Z schilly $ 00004 // Copyright (C) 2008 Mihaly Csaba Markot 00005 // 00006 // This file is part of the COCONUT API. This library 00007 // is free software; you can redistribute it and/or modify it under the 00008 // terms of the Library GNU General Public License as published by the 00009 // Free Software Foundation; either version 2, or (at your option) 00010 // any later version. 00011 00012 // This library is distributed in the hope that it will be useful, 00013 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00014 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00015 // Library GNU General Public License for more details. 00016 00017 // As a special exception, you may use this file as part of a free software 00018 // library without restriction. Specifically, if other files instantiate 00019 // templates or use macros or inline functions from this file, or you compile 00020 // this file and link it with other files to produce an executable, this 00021 // file does not by itself cause the resulting executable to be covered by 00022 // the Library GNU General Public License. This exception does not however 00023 // invalidate any other reasons why the executable file might be covered by 00024 // the Library GNU General Public License. 00025 00028 #ifndef _LOCOPT_RET_H_ 00029 #define _LOCOPT_RET_H_ 00030 00031 #include <string> 00032 #include <map> 00033 00034 #include <termreason.h> 00035 #include <inference_engine.h> 00036 #include <api_exception.h> 00037 00038 namespace coco { 00039 00040 // definitions of possible return values of the local optimization IEs: 00041 // SUCCESS: optimal solution found 00042 // PARTSUCC: partial success, approximate optimal solution found, 00043 // tolerance cannot be satisfied, no further improvement, etc. 00044 // INFEAS: problem is claimed infeasible 00045 // UNBND: problem is claimed unbounded 00046 // LIMIT: built-in limit exceeded, user requested stop 00047 // ERROR: return messages of any other type, interpreted as errors 00048 #define LOPT_SUCCESS 0 00049 #define LOPT_PARTSUCC 1 00050 #define LOPT_INFEAS 2 00051 #define LOPT_UNBND 3 00052 #define LOPT_LIMIT 4 00053 #define LOPT_ERROR 5 00054 00055 // definitions of the return weights of the local optimization IEs 00056 #define LOPT_WGHT_SUCCESS 10.0 00057 #define LOPT_WGHT_PARTSUCC 5.0 00058 #define LOPT_WGHT_INFEAS 3.0 00059 #define LOPT_WGHT_UNBND 3.0 00060 #define LOPT_WGHT_LIMIT 1.0 00061 #define LOPT_WGHT_ERROR 0.0 00062 00063 class locopt_ret_record; 00064 00065 // the information related to the IE return is stored in the map below. The key 00066 // is the solver status code (note the difference between this and the IE return 00067 // code!). 00068 typedef std::map<int,locopt_ret_record> locopt_ret; 00069 00070 // determines IE return weight associated to the solver return value srval 00071 // from the ret_info map 00072 double get_locopt_weight_from_rval(const locopt_ret& ret_info, 00073 const std::string& iename, const int srval); 00074 00075 // determines IE termination reason associated to the solver return value srval 00076 // from the ret_info map 00077 termination_reason get_locopt_termr_from_rval(const locopt_ret& ret_info, 00078 const std::string& iename, const int srval); 00079 00080 // A record of local optimization return stuff: it consists of a termination 00081 // message and the inference engine return value (encapsulated into a 00082 // termination_reason object) and the inference engine return weight. 00083 // The return values and weights are classified for each local optimization IE 00084 // by the LOPT_* and LOPT_RWGHT_* values defined above. 00085 class locopt_ret_record 00086 { 00087 private: 00088 termination_reason termr; // termination reason (message + IE return value) 00089 double weight; // IE return weight 00090 00092 void set_weight(const int val) 00093 { 00094 switch (val) 00095 { 00096 case (LOPT_SUCCESS): 00097 weight = LOPT_WGHT_SUCCESS; 00098 break; 00099 case (LOPT_PARTSUCC): 00100 weight = LOPT_WGHT_PARTSUCC; 00101 break; 00102 case (LOPT_INFEAS): 00103 weight = LOPT_WGHT_INFEAS; 00104 break; 00105 case (LOPT_UNBND): 00106 weight = LOPT_WGHT_UNBND; 00107 break; 00108 case (LOPT_LIMIT): 00109 weight = LOPT_WGHT_LIMIT; 00110 break; 00111 case (LOPT_ERROR): 00112 weight = LOPT_WGHT_ERROR; 00113 break; 00114 default: 00115 throw api_exception(apiee_internal, 00116 std::string("locopt_ret_record::set_weight(): undefined return " 00117 "value")); 00118 } 00119 } 00120 00121 public: 00123 locopt_ret_record() 00124 : termr() { set_weight(termr.get_code()); } 00125 00126 locopt_ret_record(const termination_reason& t) 00127 : termr(t) { set_weight(termr.get_code()); } 00128 00129 locopt_ret_record(const std::string& t_msg, int t_code) 00130 : termr(t_code,t_msg) { set_weight(t_code); } 00131 00133 locopt_ret_record(const locopt_ret_record& r) 00134 : termr(r.termr), weight(r.weight) {} 00135 00137 locopt_ret_record& operator=(const locopt_ret_record& r) 00138 { 00139 if (&r != this) 00140 { 00141 termr = r.termr; 00142 weight = r.weight; 00143 } 00144 return *this; 00145 } 00146 00148 const termination_reason& get_termr() const { return termr; } 00149 00151 const std::string& get_message() const { return termr.get_message(); } 00152 00154 int get_code() const { return termr.get_code(); } 00155 00157 double get_weight() const { return weight; } 00158 00159 }; 00160 00161 } // namespace coco 00162 00163 #endif /* _LOCOPT_RET_H_*/