... | ... |
@@ -974,194 +974,194 @@ |
974 | 974 |
virtual void _clear() = 0; |
975 | 975 |
|
976 | 976 |
virtual const char* _solverName() const = 0; |
977 | 977 |
|
978 | 978 |
//Own protected stuff |
979 | 979 |
|
980 | 980 |
//Constant component of the objective function |
981 | 981 |
Value obj_const_comp; |
982 | 982 |
|
983 | 983 |
LpBase() : rows(), cols(), obj_const_comp(0) {} |
984 | 984 |
|
985 | 985 |
public: |
986 | 986 |
|
987 | 987 |
/// Virtual destructor |
988 | 988 |
virtual ~LpBase() {} |
989 | 989 |
|
990 | 990 |
///Creates a new LP problem |
991 | 991 |
LpBase* newSolver() {return _newSolver();} |
992 | 992 |
///Makes a copy of the LP problem |
993 | 993 |
LpBase* cloneSolver() {return _cloneSolver();} |
994 | 994 |
|
995 | 995 |
///Gives back the name of the solver. |
996 | 996 |
const char* solverName() const {return _solverName();} |
997 | 997 |
|
998 | 998 |
///\name Build up and modify the LP |
999 | 999 |
|
1000 | 1000 |
///@{ |
1001 | 1001 |
|
1002 | 1002 |
///Add a new empty column (i.e a new variable) to the LP |
1003 | 1003 |
Col addCol() { Col c; c._id = _addColId(_addCol()); return c;} |
1004 | 1004 |
|
1005 | 1005 |
///\brief Adds several new columns (i.e variables) at once |
1006 | 1006 |
/// |
1007 | 1007 |
///This magic function takes a container as its argument and fills |
1008 | 1008 |
///its elements with new columns (i.e. variables) |
1009 | 1009 |
///\param t can be |
1010 | 1010 |
///- a standard STL compatible iterable container with |
1011 | 1011 |
///\ref Col as its \c values_type like |
1012 | 1012 |
///\code |
1013 | 1013 |
///std::vector<LpBase::Col> |
1014 | 1014 |
///std::list<LpBase::Col> |
1015 | 1015 |
///\endcode |
1016 | 1016 |
///- a standard STL compatible iterable container with |
1017 | 1017 |
///\ref Col as its \c mapped_type like |
1018 | 1018 |
///\code |
1019 | 1019 |
///std::map<AnyType,LpBase::Col> |
1020 | 1020 |
///\endcode |
1021 | 1021 |
///- an iterable lemon \ref concepts::WriteMap "write map" like |
1022 | 1022 |
///\code |
1023 | 1023 |
///ListGraph::NodeMap<LpBase::Col> |
1024 | 1024 |
///ListGraph::ArcMap<LpBase::Col> |
1025 | 1025 |
///\endcode |
1026 | 1026 |
///\return The number of the created column. |
1027 | 1027 |
#ifdef DOXYGEN |
1028 | 1028 |
template<class T> |
1029 | 1029 |
int addColSet(T &t) { return 0;} |
1030 | 1030 |
#else |
1031 | 1031 |
template<class T> |
1032 | 1032 |
typename enable_if<typename T::value_type::LpCol,int>::type |
1033 | 1033 |
addColSet(T &t,dummy<0> = 0) { |
1034 | 1034 |
int s=0; |
1035 | 1035 |
for(typename T::iterator i=t.begin();i!=t.end();++i) {*i=addCol();s++;} |
1036 | 1036 |
return s; |
1037 | 1037 |
} |
1038 | 1038 |
template<class T> |
1039 | 1039 |
typename enable_if<typename T::value_type::second_type::LpCol, |
1040 | 1040 |
int>::type |
1041 | 1041 |
addColSet(T &t,dummy<1> = 1) { |
1042 | 1042 |
int s=0; |
1043 | 1043 |
for(typename T::iterator i=t.begin();i!=t.end();++i) { |
1044 | 1044 |
i->second=addCol(); |
1045 | 1045 |
s++; |
1046 | 1046 |
} |
1047 | 1047 |
return s; |
1048 | 1048 |
} |
1049 | 1049 |
template<class T> |
1050 | 1050 |
typename enable_if<typename T::MapIt::Value::LpCol, |
1051 | 1051 |
int>::type |
1052 | 1052 |
addColSet(T &t,dummy<2> = 2) { |
1053 | 1053 |
int s=0; |
1054 | 1054 |
for(typename T::MapIt i(t); i!=INVALID; ++i) |
1055 | 1055 |
{ |
1056 | 1056 |
i.set(addCol()); |
1057 | 1057 |
s++; |
1058 | 1058 |
} |
1059 | 1059 |
return s; |
1060 | 1060 |
} |
1061 | 1061 |
#endif |
1062 | 1062 |
|
1063 | 1063 |
///Set a column (i.e a dual constraint) of the LP |
1064 | 1064 |
|
1065 | 1065 |
///\param c is the column to be modified |
1066 | 1066 |
///\param e is a dual linear expression (see \ref DualExpr) |
1067 | 1067 |
///a better one. |
1068 | 1068 |
void col(Col c, const DualExpr &e) { |
1069 | 1069 |
e.simplify(); |
1070 |
_setColCoeffs(cols(id(c)), ExprIterator(e.comps.begin(), cols), |
|
1071 |
ExprIterator(e.comps.end(), cols)); |
|
1070 |
_setColCoeffs(cols(id(c)), ExprIterator(e.comps.begin(), rows), |
|
1071 |
ExprIterator(e.comps.end(), rows)); |
|
1072 | 1072 |
} |
1073 | 1073 |
|
1074 | 1074 |
///Get a column (i.e a dual constraint) of the LP |
1075 | 1075 |
|
1076 | 1076 |
///\param c is the column to get |
1077 | 1077 |
///\return the dual expression associated to the column |
1078 | 1078 |
DualExpr col(Col c) const { |
1079 | 1079 |
DualExpr e; |
1080 | 1080 |
_getColCoeffs(cols(id(c)), InsertIterator(e.comps, rows)); |
1081 | 1081 |
return e; |
1082 | 1082 |
} |
1083 | 1083 |
|
1084 | 1084 |
///Add a new column to the LP |
1085 | 1085 |
|
1086 | 1086 |
///\param e is a dual linear expression (see \ref DualExpr) |
1087 | 1087 |
///\param o is the corresponding component of the objective |
1088 | 1088 |
///function. It is 0 by default. |
1089 | 1089 |
///\return The created column. |
1090 | 1090 |
Col addCol(const DualExpr &e, Value o = 0) { |
1091 | 1091 |
Col c=addCol(); |
1092 | 1092 |
col(c,e); |
1093 | 1093 |
objCoeff(c,o); |
1094 | 1094 |
return c; |
1095 | 1095 |
} |
1096 | 1096 |
|
1097 | 1097 |
///Add a new empty row (i.e a new constraint) to the LP |
1098 | 1098 |
|
1099 | 1099 |
///This function adds a new empty row (i.e a new constraint) to the LP. |
1100 | 1100 |
///\return The created row |
1101 | 1101 |
Row addRow() { Row r; r._id = _addRowId(_addRow()); return r;} |
1102 | 1102 |
|
1103 | 1103 |
///\brief Add several new rows (i.e constraints) at once |
1104 | 1104 |
/// |
1105 | 1105 |
///This magic function takes a container as its argument and fills |
1106 | 1106 |
///its elements with new row (i.e. variables) |
1107 | 1107 |
///\param t can be |
1108 | 1108 |
///- a standard STL compatible iterable container with |
1109 | 1109 |
///\ref Row as its \c values_type like |
1110 | 1110 |
///\code |
1111 | 1111 |
///std::vector<LpBase::Row> |
1112 | 1112 |
///std::list<LpBase::Row> |
1113 | 1113 |
///\endcode |
1114 | 1114 |
///- a standard STL compatible iterable container with |
1115 | 1115 |
///\ref Row as its \c mapped_type like |
1116 | 1116 |
///\code |
1117 | 1117 |
///std::map<AnyType,LpBase::Row> |
1118 | 1118 |
///\endcode |
1119 | 1119 |
///- an iterable lemon \ref concepts::WriteMap "write map" like |
1120 | 1120 |
///\code |
1121 | 1121 |
///ListGraph::NodeMap<LpBase::Row> |
1122 | 1122 |
///ListGraph::ArcMap<LpBase::Row> |
1123 | 1123 |
///\endcode |
1124 | 1124 |
///\return The number of rows created. |
1125 | 1125 |
#ifdef DOXYGEN |
1126 | 1126 |
template<class T> |
1127 | 1127 |
int addRowSet(T &t) { return 0;} |
1128 | 1128 |
#else |
1129 | 1129 |
template<class T> |
1130 | 1130 |
typename enable_if<typename T::value_type::LpRow,int>::type |
1131 | 1131 |
addRowSet(T &t, dummy<0> = 0) { |
1132 | 1132 |
int s=0; |
1133 | 1133 |
for(typename T::iterator i=t.begin();i!=t.end();++i) {*i=addRow();s++;} |
1134 | 1134 |
return s; |
1135 | 1135 |
} |
1136 | 1136 |
template<class T> |
1137 | 1137 |
typename enable_if<typename T::value_type::second_type::LpRow, int>::type |
1138 | 1138 |
addRowSet(T &t, dummy<1> = 1) { |
1139 | 1139 |
int s=0; |
1140 | 1140 |
for(typename T::iterator i=t.begin();i!=t.end();++i) { |
1141 | 1141 |
i->second=addRow(); |
1142 | 1142 |
s++; |
1143 | 1143 |
} |
1144 | 1144 |
return s; |
1145 | 1145 |
} |
1146 | 1146 |
template<class T> |
1147 | 1147 |
typename enable_if<typename T::MapIt::Value::LpRow, int>::type |
1148 | 1148 |
addRowSet(T &t, dummy<2> = 2) { |
1149 | 1149 |
int s=0; |
1150 | 1150 |
for(typename T::MapIt i(t); i!=INVALID; ++i) |
1151 | 1151 |
{ |
1152 | 1152 |
i.set(addRow()); |
1153 | 1153 |
s++; |
1154 | 1154 |
} |
1155 | 1155 |
return s; |
1156 | 1156 |
} |
1157 | 1157 |
#endif |
1158 | 1158 |
|
1159 | 1159 |
///Set a row (i.e a constraint) of the LP |
1160 | 1160 |
|
1161 | 1161 |
///\param r is the row to be modified |
1162 | 1162 |
///\param l is lower bound (-\ref INF means no bound) |
1163 | 1163 |
///\param e is a linear expression (see \ref Expr) |
1164 | 1164 |
///\param u is the upper bound (\ref INF means no bound) |
1165 | 1165 |
void row(Row r, Value l, const Expr &e, Value u) { |
1166 | 1166 |
e.simplify(); |
1167 | 1167 |
_setRowCoeffs(rows(id(r)), ExprIterator(e.comps.begin(), cols), |
0 comments (0 inline)