gravatar
deba@inf.elte.hu
deba@inf.elte.hu
Fix LpBase::addRow(Constr) (#334)
0 1 0
default
1 file changed with 2 insertions and 2 deletions:
↑ Collapse diff ↑
Ignore white space 768 line context
... ...
@@ -848,772 +848,772 @@
848 848

	
849 849

	
850 850
  protected:
851 851

	
852 852
    class InsertIterator {
853 853
    private:
854 854

	
855 855
      std::map<int, Value>& _host;
856 856
      const _solver_bits::VarIndex& _index;
857 857

	
858 858
    public:
859 859

	
860 860
      typedef std::output_iterator_tag iterator_category;
861 861
      typedef void difference_type;
862 862
      typedef void value_type;
863 863
      typedef void reference;
864 864
      typedef void pointer;
865 865

	
866 866
      InsertIterator(std::map<int, Value>& host,
867 867
                   const _solver_bits::VarIndex& index)
868 868
        : _host(host), _index(index) {}
869 869

	
870 870
      InsertIterator& operator=(const std::pair<int, Value>& value) {
871 871
        typedef std::map<int, Value>::value_type pair_type;
872 872
        _host.insert(pair_type(_index[value.first], value.second));
873 873
        return *this;
874 874
      }
875 875

	
876 876
      InsertIterator& operator*() { return *this; }
877 877
      InsertIterator& operator++() { return *this; }
878 878
      InsertIterator operator++(int) { return *this; }
879 879

	
880 880
    };
881 881

	
882 882
    class ExprIterator {
883 883
    private:
884 884
      std::map<int, Value>::const_iterator _host_it;
885 885
      const _solver_bits::VarIndex& _index;
886 886
    public:
887 887

	
888 888
      typedef std::bidirectional_iterator_tag iterator_category;
889 889
      typedef std::ptrdiff_t difference_type;
890 890
      typedef const std::pair<int, Value> value_type;
891 891
      typedef value_type reference;
892 892

	
893 893
      class pointer {
894 894
      public:
895 895
        pointer(value_type& _value) : value(_value) {}
896 896
        value_type* operator->() { return &value; }
897 897
      private:
898 898
        value_type value;
899 899
      };
900 900

	
901 901
      ExprIterator(const std::map<int, Value>::const_iterator& host_it,
902 902
                   const _solver_bits::VarIndex& index)
903 903
        : _host_it(host_it), _index(index) {}
904 904

	
905 905
      reference operator*() {
906 906
        return std::make_pair(_index(_host_it->first), _host_it->second);
907 907
      }
908 908

	
909 909
      pointer operator->() {
910 910
        return pointer(operator*());
911 911
      }
912 912

	
913 913
      ExprIterator& operator++() { ++_host_it; return *this; }
914 914
      ExprIterator operator++(int) {
915 915
        ExprIterator tmp(*this); ++_host_it; return tmp;
916 916
      }
917 917

	
918 918
      ExprIterator& operator--() { --_host_it; return *this; }
919 919
      ExprIterator operator--(int) {
920 920
        ExprIterator tmp(*this); --_host_it; return tmp;
921 921
      }
922 922

	
923 923
      bool operator==(const ExprIterator& it) const {
924 924
        return _host_it == it._host_it;
925 925
      }
926 926

	
927 927
      bool operator!=(const ExprIterator& it) const {
928 928
        return _host_it != it._host_it;
929 929
      }
930 930

	
931 931
    };
932 932

	
933 933
  protected:
934 934

	
935 935
    //Abstract virtual functions
936 936

	
937 937
    virtual int _addColId(int col) { return cols.addIndex(col); }
938 938
    virtual int _addRowId(int row) { return rows.addIndex(row); }
939 939

	
940 940
    virtual void _eraseColId(int col) { cols.eraseIndex(col); }
941 941
    virtual void _eraseRowId(int row) { rows.eraseIndex(row); }
942 942

	
943 943
    virtual int _addCol() = 0;
944 944
    virtual int _addRow() = 0;
945 945

	
946 946
    virtual int _addRow(Value l, ExprIterator b, ExprIterator e, Value u) {
947 947
      int row = _addRow();
948 948
      _setRowCoeffs(row, b, e);
949 949
      _setRowLowerBound(row, l);
950 950
      _setRowUpperBound(row, u);
951 951
      return row;
952 952
    }
953 953

	
954 954
    virtual void _eraseCol(int col) = 0;
955 955
    virtual void _eraseRow(int row) = 0;
956 956

	
957 957
    virtual void _getColName(int col, std::string& name) const = 0;
958 958
    virtual void _setColName(int col, const std::string& name) = 0;
959 959
    virtual int _colByName(const std::string& name) const = 0;
960 960

	
961 961
    virtual void _getRowName(int row, std::string& name) const = 0;
962 962
    virtual void _setRowName(int row, const std::string& name) = 0;
963 963
    virtual int _rowByName(const std::string& name) const = 0;
964 964

	
965 965
    virtual void _setRowCoeffs(int i, ExprIterator b, ExprIterator e) = 0;
966 966
    virtual void _getRowCoeffs(int i, InsertIterator b) const = 0;
967 967

	
968 968
    virtual void _setColCoeffs(int i, ExprIterator b, ExprIterator e) = 0;
969 969
    virtual void _getColCoeffs(int i, InsertIterator b) const = 0;
970 970

	
971 971
    virtual void _setCoeff(int row, int col, Value value) = 0;
972 972
    virtual Value _getCoeff(int row, int col) const = 0;
973 973

	
974 974
    virtual void _setColLowerBound(int i, Value value) = 0;
975 975
    virtual Value _getColLowerBound(int i) const = 0;
976 976

	
977 977
    virtual void _setColUpperBound(int i, Value value) = 0;
978 978
    virtual Value _getColUpperBound(int i) const = 0;
979 979

	
980 980
    virtual void _setRowLowerBound(int i, Value value) = 0;
981 981
    virtual Value _getRowLowerBound(int i) const = 0;
982 982

	
983 983
    virtual void _setRowUpperBound(int i, Value value) = 0;
984 984
    virtual Value _getRowUpperBound(int i) const = 0;
985 985

	
986 986
    virtual void _setObjCoeffs(ExprIterator b, ExprIterator e) = 0;
987 987
    virtual void _getObjCoeffs(InsertIterator b) const = 0;
988 988

	
989 989
    virtual void _setObjCoeff(int i, Value obj_coef) = 0;
990 990
    virtual Value _getObjCoeff(int i) const = 0;
991 991

	
992 992
    virtual void _setSense(Sense) = 0;
993 993
    virtual Sense _getSense() const = 0;
994 994

	
995 995
    virtual void _clear() = 0;
996 996

	
997 997
    virtual const char* _solverName() const = 0;
998 998

	
999 999
    virtual void _messageLevel(MessageLevel level) = 0;
1000 1000

	
1001 1001
    //Own protected stuff
1002 1002

	
1003 1003
    //Constant component of the objective function
1004 1004
    Value obj_const_comp;
1005 1005

	
1006 1006
    LpBase() : rows(), cols(), obj_const_comp(0) {}
1007 1007

	
1008 1008
  public:
1009 1009

	
1010 1010
    /// Virtual destructor
1011 1011
    virtual ~LpBase() {}
1012 1012

	
1013 1013
    ///Gives back the name of the solver.
1014 1014
    const char* solverName() const {return _solverName();}
1015 1015

	
1016 1016
    ///\name Build Up and Modify the LP
1017 1017

	
1018 1018
    ///@{
1019 1019

	
1020 1020
    ///Add a new empty column (i.e a new variable) to the LP
1021 1021
    Col addCol() { Col c; c._id = _addColId(_addCol()); return c;}
1022 1022

	
1023 1023
    ///\brief Adds several new columns (i.e variables) at once
1024 1024
    ///
1025 1025
    ///This magic function takes a container as its argument and fills
1026 1026
    ///its elements with new columns (i.e. variables)
1027 1027
    ///\param t can be
1028 1028
    ///- a standard STL compatible iterable container with
1029 1029
    ///\ref Col as its \c values_type like
1030 1030
    ///\code
1031 1031
    ///std::vector<LpBase::Col>
1032 1032
    ///std::list<LpBase::Col>
1033 1033
    ///\endcode
1034 1034
    ///- a standard STL compatible iterable container with
1035 1035
    ///\ref Col as its \c mapped_type like
1036 1036
    ///\code
1037 1037
    ///std::map<AnyType,LpBase::Col>
1038 1038
    ///\endcode
1039 1039
    ///- an iterable lemon \ref concepts::WriteMap "write map" like
1040 1040
    ///\code
1041 1041
    ///ListGraph::NodeMap<LpBase::Col>
1042 1042
    ///ListGraph::ArcMap<LpBase::Col>
1043 1043
    ///\endcode
1044 1044
    ///\return The number of the created column.
1045 1045
#ifdef DOXYGEN
1046 1046
    template<class T>
1047 1047
    int addColSet(T &t) { return 0;}
1048 1048
#else
1049 1049
    template<class T>
1050 1050
    typename enable_if<typename T::value_type::LpCol,int>::type
1051 1051
    addColSet(T &t,dummy<0> = 0) {
1052 1052
      int s=0;
1053 1053
      for(typename T::iterator i=t.begin();i!=t.end();++i) {*i=addCol();s++;}
1054 1054
      return s;
1055 1055
    }
1056 1056
    template<class T>
1057 1057
    typename enable_if<typename T::value_type::second_type::LpCol,
1058 1058
                       int>::type
1059 1059
    addColSet(T &t,dummy<1> = 1) {
1060 1060
      int s=0;
1061 1061
      for(typename T::iterator i=t.begin();i!=t.end();++i) {
1062 1062
        i->second=addCol();
1063 1063
        s++;
1064 1064
      }
1065 1065
      return s;
1066 1066
    }
1067 1067
    template<class T>
1068 1068
    typename enable_if<typename T::MapIt::Value::LpCol,
1069 1069
                       int>::type
1070 1070
    addColSet(T &t,dummy<2> = 2) {
1071 1071
      int s=0;
1072 1072
      for(typename T::MapIt i(t); i!=INVALID; ++i)
1073 1073
        {
1074 1074
          i.set(addCol());
1075 1075
          s++;
1076 1076
        }
1077 1077
      return s;
1078 1078
    }
1079 1079
#endif
1080 1080

	
1081 1081
    ///Set a column (i.e a dual constraint) of the LP
1082 1082

	
1083 1083
    ///\param c is the column to be modified
1084 1084
    ///\param e is a dual linear expression (see \ref DualExpr)
1085 1085
    ///a better one.
1086 1086
    void col(Col c, const DualExpr &e) {
1087 1087
      e.simplify();
1088 1088
      _setColCoeffs(cols(id(c)), ExprIterator(e.comps.begin(), rows),
1089 1089
                    ExprIterator(e.comps.end(), rows));
1090 1090
    }
1091 1091

	
1092 1092
    ///Get a column (i.e a dual constraint) of the LP
1093 1093

	
1094 1094
    ///\param c is the column to get
1095 1095
    ///\return the dual expression associated to the column
1096 1096
    DualExpr col(Col c) const {
1097 1097
      DualExpr e;
1098 1098
      _getColCoeffs(cols(id(c)), InsertIterator(e.comps, rows));
1099 1099
      return e;
1100 1100
    }
1101 1101

	
1102 1102
    ///Add a new column to the LP
1103 1103

	
1104 1104
    ///\param e is a dual linear expression (see \ref DualExpr)
1105 1105
    ///\param o is the corresponding component of the objective
1106 1106
    ///function. It is 0 by default.
1107 1107
    ///\return The created column.
1108 1108
    Col addCol(const DualExpr &e, Value o = 0) {
1109 1109
      Col c=addCol();
1110 1110
      col(c,e);
1111 1111
      objCoeff(c,o);
1112 1112
      return c;
1113 1113
    }
1114 1114

	
1115 1115
    ///Add a new empty row (i.e a new constraint) to the LP
1116 1116

	
1117 1117
    ///This function adds a new empty row (i.e a new constraint) to the LP.
1118 1118
    ///\return The created row
1119 1119
    Row addRow() { Row r; r._id = _addRowId(_addRow()); return r;}
1120 1120

	
1121 1121
    ///\brief Add several new rows (i.e constraints) at once
1122 1122
    ///
1123 1123
    ///This magic function takes a container as its argument and fills
1124 1124
    ///its elements with new row (i.e. variables)
1125 1125
    ///\param t can be
1126 1126
    ///- a standard STL compatible iterable container with
1127 1127
    ///\ref Row as its \c values_type like
1128 1128
    ///\code
1129 1129
    ///std::vector<LpBase::Row>
1130 1130
    ///std::list<LpBase::Row>
1131 1131
    ///\endcode
1132 1132
    ///- a standard STL compatible iterable container with
1133 1133
    ///\ref Row as its \c mapped_type like
1134 1134
    ///\code
1135 1135
    ///std::map<AnyType,LpBase::Row>
1136 1136
    ///\endcode
1137 1137
    ///- an iterable lemon \ref concepts::WriteMap "write map" like
1138 1138
    ///\code
1139 1139
    ///ListGraph::NodeMap<LpBase::Row>
1140 1140
    ///ListGraph::ArcMap<LpBase::Row>
1141 1141
    ///\endcode
1142 1142
    ///\return The number of rows created.
1143 1143
#ifdef DOXYGEN
1144 1144
    template<class T>
1145 1145
    int addRowSet(T &t) { return 0;}
1146 1146
#else
1147 1147
    template<class T>
1148 1148
    typename enable_if<typename T::value_type::LpRow,int>::type
1149 1149
    addRowSet(T &t, dummy<0> = 0) {
1150 1150
      int s=0;
1151 1151
      for(typename T::iterator i=t.begin();i!=t.end();++i) {*i=addRow();s++;}
1152 1152
      return s;
1153 1153
    }
1154 1154
    template<class T>
1155 1155
    typename enable_if<typename T::value_type::second_type::LpRow, int>::type
1156 1156
    addRowSet(T &t, dummy<1> = 1) {
1157 1157
      int s=0;
1158 1158
      for(typename T::iterator i=t.begin();i!=t.end();++i) {
1159 1159
        i->second=addRow();
1160 1160
        s++;
1161 1161
      }
1162 1162
      return s;
1163 1163
    }
1164 1164
    template<class T>
1165 1165
    typename enable_if<typename T::MapIt::Value::LpRow, int>::type
1166 1166
    addRowSet(T &t, dummy<2> = 2) {
1167 1167
      int s=0;
1168 1168
      for(typename T::MapIt i(t); i!=INVALID; ++i)
1169 1169
        {
1170 1170
          i.set(addRow());
1171 1171
          s++;
1172 1172
        }
1173 1173
      return s;
1174 1174
    }
1175 1175
#endif
1176 1176

	
1177 1177
    ///Set a row (i.e a constraint) of the LP
1178 1178

	
1179 1179
    ///\param r is the row to be modified
1180 1180
    ///\param l is lower bound (-\ref INF means no bound)
1181 1181
    ///\param e is a linear expression (see \ref Expr)
1182 1182
    ///\param u is the upper bound (\ref INF means no bound)
1183 1183
    void row(Row r, Value l, const Expr &e, Value u) {
1184 1184
      e.simplify();
1185 1185
      _setRowCoeffs(rows(id(r)), ExprIterator(e.comps.begin(), cols),
1186 1186
                    ExprIterator(e.comps.end(), cols));
1187 1187
      _setRowLowerBound(rows(id(r)),l - *e);
1188 1188
      _setRowUpperBound(rows(id(r)),u - *e);
1189 1189
    }
1190 1190

	
1191 1191
    ///Set a row (i.e a constraint) of the LP
1192 1192

	
1193 1193
    ///\param r is the row to be modified
1194 1194
    ///\param c is a linear expression (see \ref Constr)
1195 1195
    void row(Row r, const Constr &c) {
1196 1196
      row(r, c.lowerBounded()?c.lowerBound():-INF,
1197 1197
          c.expr(), c.upperBounded()?c.upperBound():INF);
1198 1198
    }
1199 1199

	
1200 1200

	
1201 1201
    ///Get a row (i.e a constraint) of the LP
1202 1202

	
1203 1203
    ///\param r is the row to get
1204 1204
    ///\return the expression associated to the row
1205 1205
    Expr row(Row r) const {
1206 1206
      Expr e;
1207 1207
      _getRowCoeffs(rows(id(r)), InsertIterator(e.comps, cols));
1208 1208
      return e;
1209 1209
    }
1210 1210

	
1211 1211
    ///Add a new row (i.e a new constraint) to the LP
1212 1212

	
1213 1213
    ///\param l is the lower bound (-\ref INF means no bound)
1214 1214
    ///\param e is a linear expression (see \ref Expr)
1215 1215
    ///\param u is the upper bound (\ref INF means no bound)
1216 1216
    ///\return The created row.
1217 1217
    Row addRow(Value l,const Expr &e, Value u) {
1218 1218
      Row r;
1219 1219
      e.simplify();
1220 1220
      r._id = _addRowId(_addRow(l - *e, ExprIterator(e.comps.begin(), cols),
1221 1221
                                ExprIterator(e.comps.end(), cols), u - *e));
1222 1222
      return r;
1223 1223
    }
1224 1224

	
1225 1225
    ///Add a new row (i.e a new constraint) to the LP
1226 1226

	
1227 1227
    ///\param c is a linear expression (see \ref Constr)
1228 1228
    ///\return The created row.
1229 1229
    Row addRow(const Constr &c) {
1230 1230
      Row r;
1231 1231
      c.expr().simplify();
1232
      r._id = _addRowId(_addRow(c.lowerBounded()?c.lowerBound():-INF, 
1232
      r._id = _addRowId(_addRow(c.lowerBounded()?c.lowerBound()-*c.expr():-INF, 
1233 1233
                                ExprIterator(c.expr().comps.begin(), cols),
1234 1234
                                ExprIterator(c.expr().comps.end(), cols),
1235
                                c.upperBounded()?c.upperBound():INF));
1235
                                c.upperBounded()?c.upperBound()-*c.expr():INF));
1236 1236
      return r;
1237 1237
    }
1238 1238
    ///Erase a column (i.e a variable) from the LP
1239 1239

	
1240 1240
    ///\param c is the column to be deleted
1241 1241
    void erase(Col c) {
1242 1242
      _eraseCol(cols(id(c)));
1243 1243
      _eraseColId(cols(id(c)));
1244 1244
    }
1245 1245
    ///Erase a row (i.e a constraint) from the LP
1246 1246

	
1247 1247
    ///\param r is the row to be deleted
1248 1248
    void erase(Row r) {
1249 1249
      _eraseRow(rows(id(r)));
1250 1250
      _eraseRowId(rows(id(r)));
1251 1251
    }
1252 1252

	
1253 1253
    /// Get the name of a column
1254 1254

	
1255 1255
    ///\param c is the coresponding column
1256 1256
    ///\return The name of the colunm
1257 1257
    std::string colName(Col c) const {
1258 1258
      std::string name;
1259 1259
      _getColName(cols(id(c)), name);
1260 1260
      return name;
1261 1261
    }
1262 1262

	
1263 1263
    /// Set the name of a column
1264 1264

	
1265 1265
    ///\param c is the coresponding column
1266 1266
    ///\param name The name to be given
1267 1267
    void colName(Col c, const std::string& name) {
1268 1268
      _setColName(cols(id(c)), name);
1269 1269
    }
1270 1270

	
1271 1271
    /// Get the column by its name
1272 1272

	
1273 1273
    ///\param name The name of the column
1274 1274
    ///\return the proper column or \c INVALID
1275 1275
    Col colByName(const std::string& name) const {
1276 1276
      int k = _colByName(name);
1277 1277
      return k != -1 ? Col(cols[k]) : Col(INVALID);
1278 1278
    }
1279 1279

	
1280 1280
    /// Get the name of a row
1281 1281

	
1282 1282
    ///\param r is the coresponding row
1283 1283
    ///\return The name of the row
1284 1284
    std::string rowName(Row r) const {
1285 1285
      std::string name;
1286 1286
      _getRowName(rows(id(r)), name);
1287 1287
      return name;
1288 1288
    }
1289 1289

	
1290 1290
    /// Set the name of a row
1291 1291

	
1292 1292
    ///\param r is the coresponding row
1293 1293
    ///\param name The name to be given
1294 1294
    void rowName(Row r, const std::string& name) {
1295 1295
      _setRowName(rows(id(r)), name);
1296 1296
    }
1297 1297

	
1298 1298
    /// Get the row by its name
1299 1299

	
1300 1300
    ///\param name The name of the row
1301 1301
    ///\return the proper row or \c INVALID
1302 1302
    Row rowByName(const std::string& name) const {
1303 1303
      int k = _rowByName(name);
1304 1304
      return k != -1 ? Row(rows[k]) : Row(INVALID);
1305 1305
    }
1306 1306

	
1307 1307
    /// Set an element of the coefficient matrix of the LP
1308 1308

	
1309 1309
    ///\param r is the row of the element to be modified
1310 1310
    ///\param c is the column of the element to be modified
1311 1311
    ///\param val is the new value of the coefficient
1312 1312
    void coeff(Row r, Col c, Value val) {
1313 1313
      _setCoeff(rows(id(r)),cols(id(c)), val);
1314 1314
    }
1315 1315

	
1316 1316
    /// Get an element of the coefficient matrix of the LP
1317 1317

	
1318 1318
    ///\param r is the row of the element
1319 1319
    ///\param c is the column of the element
1320 1320
    ///\return the corresponding coefficient
1321 1321
    Value coeff(Row r, Col c) const {
1322 1322
      return _getCoeff(rows(id(r)),cols(id(c)));
1323 1323
    }
1324 1324

	
1325 1325
    /// Set the lower bound of a column (i.e a variable)
1326 1326

	
1327 1327
    /// The lower bound of a variable (column) has to be given by an
1328 1328
    /// extended number of type Value, i.e. a finite number of type
1329 1329
    /// Value or -\ref INF.
1330 1330
    void colLowerBound(Col c, Value value) {
1331 1331
      _setColLowerBound(cols(id(c)),value);
1332 1332
    }
1333 1333

	
1334 1334
    /// Get the lower bound of a column (i.e a variable)
1335 1335

	
1336 1336
    /// This function returns the lower bound for column (variable) \c c
1337 1337
    /// (this might be -\ref INF as well).
1338 1338
    ///\return The lower bound for column \c c
1339 1339
    Value colLowerBound(Col c) const {
1340 1340
      return _getColLowerBound(cols(id(c)));
1341 1341
    }
1342 1342

	
1343 1343
    ///\brief Set the lower bound of  several columns
1344 1344
    ///(i.e variables) at once
1345 1345
    ///
1346 1346
    ///This magic function takes a container as its argument
1347 1347
    ///and applies the function on all of its elements.
1348 1348
    ///The lower bound of a variable (column) has to be given by an
1349 1349
    ///extended number of type Value, i.e. a finite number of type
1350 1350
    ///Value or -\ref INF.
1351 1351
#ifdef DOXYGEN
1352 1352
    template<class T>
1353 1353
    void colLowerBound(T &t, Value value) { return 0;}
1354 1354
#else
1355 1355
    template<class T>
1356 1356
    typename enable_if<typename T::value_type::LpCol,void>::type
1357 1357
    colLowerBound(T &t, Value value,dummy<0> = 0) {
1358 1358
      for(typename T::iterator i=t.begin();i!=t.end();++i) {
1359 1359
        colLowerBound(*i, value);
1360 1360
      }
1361 1361
    }
1362 1362
    template<class T>
1363 1363
    typename enable_if<typename T::value_type::second_type::LpCol,
1364 1364
                       void>::type
1365 1365
    colLowerBound(T &t, Value value,dummy<1> = 1) {
1366 1366
      for(typename T::iterator i=t.begin();i!=t.end();++i) {
1367 1367
        colLowerBound(i->second, value);
1368 1368
      }
1369 1369
    }
1370 1370
    template<class T>
1371 1371
    typename enable_if<typename T::MapIt::Value::LpCol,
1372 1372
                       void>::type
1373 1373
    colLowerBound(T &t, Value value,dummy<2> = 2) {
1374 1374
      for(typename T::MapIt i(t); i!=INVALID; ++i){
1375 1375
        colLowerBound(*i, value);
1376 1376
      }
1377 1377
    }
1378 1378
#endif
1379 1379

	
1380 1380
    /// Set the upper bound of a column (i.e a variable)
1381 1381

	
1382 1382
    /// The upper bound of a variable (column) has to be given by an
1383 1383
    /// extended number of type Value, i.e. a finite number of type
1384 1384
    /// Value or \ref INF.
1385 1385
    void colUpperBound(Col c, Value value) {
1386 1386
      _setColUpperBound(cols(id(c)),value);
1387 1387
    };
1388 1388

	
1389 1389
    /// Get the upper bound of a column (i.e a variable)
1390 1390

	
1391 1391
    /// This function returns the upper bound for column (variable) \c c
1392 1392
    /// (this might be \ref INF as well).
1393 1393
    /// \return The upper bound for column \c c
1394 1394
    Value colUpperBound(Col c) const {
1395 1395
      return _getColUpperBound(cols(id(c)));
1396 1396
    }
1397 1397

	
1398 1398
    ///\brief Set the upper bound of  several columns
1399 1399
    ///(i.e variables) at once
1400 1400
    ///
1401 1401
    ///This magic function takes a container as its argument
1402 1402
    ///and applies the function on all of its elements.
1403 1403
    ///The upper bound of a variable (column) has to be given by an
1404 1404
    ///extended number of type Value, i.e. a finite number of type
1405 1405
    ///Value or \ref INF.
1406 1406
#ifdef DOXYGEN
1407 1407
    template<class T>
1408 1408
    void colUpperBound(T &t, Value value) { return 0;}
1409 1409
#else
1410 1410
    template<class T1>
1411 1411
    typename enable_if<typename T1::value_type::LpCol,void>::type
1412 1412
    colUpperBound(T1 &t, Value value,dummy<0> = 0) {
1413 1413
      for(typename T1::iterator i=t.begin();i!=t.end();++i) {
1414 1414
        colUpperBound(*i, value);
1415 1415
      }
1416 1416
    }
1417 1417
    template<class T1>
1418 1418
    typename enable_if<typename T1::value_type::second_type::LpCol,
1419 1419
                       void>::type
1420 1420
    colUpperBound(T1 &t, Value value,dummy<1> = 1) {
1421 1421
      for(typename T1::iterator i=t.begin();i!=t.end();++i) {
1422 1422
        colUpperBound(i->second, value);
1423 1423
      }
1424 1424
    }
1425 1425
    template<class T1>
1426 1426
    typename enable_if<typename T1::MapIt::Value::LpCol,
1427 1427
                       void>::type
1428 1428
    colUpperBound(T1 &t, Value value,dummy<2> = 2) {
1429 1429
      for(typename T1::MapIt i(t); i!=INVALID; ++i){
1430 1430
        colUpperBound(*i, value);
1431 1431
      }
1432 1432
    }
1433 1433
#endif
1434 1434

	
1435 1435
    /// Set the lower and the upper bounds of a column (i.e a variable)
1436 1436

	
1437 1437
    /// The lower and the upper bounds of
1438 1438
    /// a variable (column) have to be given by an
1439 1439
    /// extended number of type Value, i.e. a finite number of type
1440 1440
    /// Value, -\ref INF or \ref INF.
1441 1441
    void colBounds(Col c, Value lower, Value upper) {
1442 1442
      _setColLowerBound(cols(id(c)),lower);
1443 1443
      _setColUpperBound(cols(id(c)),upper);
1444 1444
    }
1445 1445

	
1446 1446
    ///\brief Set the lower and the upper bound of several columns
1447 1447
    ///(i.e variables) at once
1448 1448
    ///
1449 1449
    ///This magic function takes a container as its argument
1450 1450
    ///and applies the function on all of its elements.
1451 1451
    /// The lower and the upper bounds of
1452 1452
    /// a variable (column) have to be given by an
1453 1453
    /// extended number of type Value, i.e. a finite number of type
1454 1454
    /// Value, -\ref INF or \ref INF.
1455 1455
#ifdef DOXYGEN
1456 1456
    template<class T>
1457 1457
    void colBounds(T &t, Value lower, Value upper) { return 0;}
1458 1458
#else
1459 1459
    template<class T2>
1460 1460
    typename enable_if<typename T2::value_type::LpCol,void>::type
1461 1461
    colBounds(T2 &t, Value lower, Value upper,dummy<0> = 0) {
1462 1462
      for(typename T2::iterator i=t.begin();i!=t.end();++i) {
1463 1463
        colBounds(*i, lower, upper);
1464 1464
      }
1465 1465
    }
1466 1466
    template<class T2>
1467 1467
    typename enable_if<typename T2::value_type::second_type::LpCol, void>::type
1468 1468
    colBounds(T2 &t, Value lower, Value upper,dummy<1> = 1) {
1469 1469
      for(typename T2::iterator i=t.begin();i!=t.end();++i) {
1470 1470
        colBounds(i->second, lower, upper);
1471 1471
      }
1472 1472
    }
1473 1473
    template<class T2>
1474 1474
    typename enable_if<typename T2::MapIt::Value::LpCol, void>::type
1475 1475
    colBounds(T2 &t, Value lower, Value upper,dummy<2> = 2) {
1476 1476
      for(typename T2::MapIt i(t); i!=INVALID; ++i){
1477 1477
        colBounds(*i, lower, upper);
1478 1478
      }
1479 1479
    }
1480 1480
#endif
1481 1481

	
1482 1482
    /// Set the lower bound of a row (i.e a constraint)
1483 1483

	
1484 1484
    /// The lower bound of a constraint (row) has to be given by an
1485 1485
    /// extended number of type Value, i.e. a finite number of type
1486 1486
    /// Value or -\ref INF.
1487 1487
    void rowLowerBound(Row r, Value value) {
1488 1488
      _setRowLowerBound(rows(id(r)),value);
1489 1489
    }
1490 1490

	
1491 1491
    /// Get the lower bound of a row (i.e a constraint)
1492 1492

	
1493 1493
    /// This function returns the lower bound for row (constraint) \c c
1494 1494
    /// (this might be -\ref INF as well).
1495 1495
    ///\return The lower bound for row \c r
1496 1496
    Value rowLowerBound(Row r) const {
1497 1497
      return _getRowLowerBound(rows(id(r)));
1498 1498
    }
1499 1499

	
1500 1500
    /// Set the upper bound of a row (i.e a constraint)
1501 1501

	
1502 1502
    /// The upper bound of a constraint (row) has to be given by an
1503 1503
    /// extended number of type Value, i.e. a finite number of type
1504 1504
    /// Value or -\ref INF.
1505 1505
    void rowUpperBound(Row r, Value value) {
1506 1506
      _setRowUpperBound(rows(id(r)),value);
1507 1507
    }
1508 1508

	
1509 1509
    /// Get the upper bound of a row (i.e a constraint)
1510 1510

	
1511 1511
    /// This function returns the upper bound for row (constraint) \c c
1512 1512
    /// (this might be -\ref INF as well).
1513 1513
    ///\return The upper bound for row \c r
1514 1514
    Value rowUpperBound(Row r) const {
1515 1515
      return _getRowUpperBound(rows(id(r)));
1516 1516
    }
1517 1517

	
1518 1518
    ///Set an element of the objective function
1519 1519
    void objCoeff(Col c, Value v) {_setObjCoeff(cols(id(c)),v); };
1520 1520

	
1521 1521
    ///Get an element of the objective function
1522 1522
    Value objCoeff(Col c) const { return _getObjCoeff(cols(id(c))); };
1523 1523

	
1524 1524
    ///Set the objective function
1525 1525

	
1526 1526
    ///\param e is a linear expression of type \ref Expr.
1527 1527
    ///
1528 1528
    void obj(const Expr& e) {
1529 1529
      _setObjCoeffs(ExprIterator(e.comps.begin(), cols),
1530 1530
                    ExprIterator(e.comps.end(), cols));
1531 1531
      obj_const_comp = *e;
1532 1532
    }
1533 1533

	
1534 1534
    ///Get the objective function
1535 1535

	
1536 1536
    ///\return the objective function as a linear expression of type
1537 1537
    ///Expr.
1538 1538
    Expr obj() const {
1539 1539
      Expr e;
1540 1540
      _getObjCoeffs(InsertIterator(e.comps, cols));
1541 1541
      *e = obj_const_comp;
1542 1542
      return e;
1543 1543
    }
1544 1544

	
1545 1545

	
1546 1546
    ///Set the direction of optimization
1547 1547
    void sense(Sense sense) { _setSense(sense); }
1548 1548

	
1549 1549
    ///Query the direction of the optimization
1550 1550
    Sense sense() const {return _getSense(); }
1551 1551

	
1552 1552
    ///Set the sense to maximization
1553 1553
    void max() { _setSense(MAX); }
1554 1554

	
1555 1555
    ///Set the sense to maximization
1556 1556
    void min() { _setSense(MIN); }
1557 1557

	
1558 1558
    ///Clears the problem
1559 1559
    void clear() { _clear(); }
1560 1560

	
1561 1561
    /// Sets the message level of the solver
1562 1562
    void messageLevel(MessageLevel level) { _messageLevel(level); }
1563 1563

	
1564 1564
    ///@}
1565 1565

	
1566 1566
  };
1567 1567

	
1568 1568
  /// Addition
1569 1569

	
1570 1570
  ///\relates LpBase::Expr
1571 1571
  ///
1572 1572
  inline LpBase::Expr operator+(const LpBase::Expr &a, const LpBase::Expr &b) {
1573 1573
    LpBase::Expr tmp(a);
1574 1574
    tmp+=b;
1575 1575
    return tmp;
1576 1576
  }
1577 1577
  ///Substraction
1578 1578

	
1579 1579
  ///\relates LpBase::Expr
1580 1580
  ///
1581 1581
  inline LpBase::Expr operator-(const LpBase::Expr &a, const LpBase::Expr &b) {
1582 1582
    LpBase::Expr tmp(a);
1583 1583
    tmp-=b;
1584 1584
    return tmp;
1585 1585
  }
1586 1586
  ///Multiply with constant
1587 1587

	
1588 1588
  ///\relates LpBase::Expr
1589 1589
  ///
1590 1590
  inline LpBase::Expr operator*(const LpBase::Expr &a, const LpBase::Value &b) {
1591 1591
    LpBase::Expr tmp(a);
1592 1592
    tmp*=b;
1593 1593
    return tmp;
1594 1594
  }
1595 1595

	
1596 1596
  ///Multiply with constant
1597 1597

	
1598 1598
  ///\relates LpBase::Expr
1599 1599
  ///
1600 1600
  inline LpBase::Expr operator*(const LpBase::Value &a, const LpBase::Expr &b) {
1601 1601
    LpBase::Expr tmp(b);
1602 1602
    tmp*=a;
1603 1603
    return tmp;
1604 1604
  }
1605 1605
  ///Divide with constant
1606 1606

	
1607 1607
  ///\relates LpBase::Expr
1608 1608
  ///
1609 1609
  inline LpBase::Expr operator/(const LpBase::Expr &a, const LpBase::Value &b) {
1610 1610
    LpBase::Expr tmp(a);
1611 1611
    tmp/=b;
1612 1612
    return tmp;
1613 1613
  }
1614 1614

	
1615 1615
  ///Create constraint
1616 1616

	
1617 1617
  ///\relates LpBase::Constr
1618 1618
  ///
1619 1619
  inline LpBase::Constr operator<=(const LpBase::Expr &e,
0 comments (0 inline)