00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014 #ifndef EXAMPLES_GLOBAL_ARITH_H_
00015 #define EXAMPLES_GLOBAL_ARITH_H_
00016 namespace operations_research {
00017 class ArithmeticPropagator;
00018 class ArithmeticConstraint;
00019
00020 class ConstraintRef {
00021 public:
00022 ConstraintRef(int index) : index_(index) {}
00023 int index() const { return index_; }
00024 private:
00025 const int index_;
00026 };
00027
00028 class GlobalArithmeticConstraint : public Constraint {
00029 public:
00030 GlobalArithmeticConstraint(Solver* const solver);
00031 virtual ~GlobalArithmeticConstraint();
00032
00033 virtual void Post();
00034 virtual void InitialPropagate();
00035 void Update(int var_index);
00036
00037 ConstraintRef MakeScalProdGreaterOrEqualConstant(
00038 const vector<IntVar*> vars,
00039 const vector<int64> coefficients,
00040 int64 constant);
00041 ConstraintRef MakeScalProdLessOrEqualConstant(
00042 const vector<IntVar*> vars,
00043 const vector<int64> coefficients,
00044 int64 constant);
00045 ConstraintRef MakeScalProdEqualConstant(const vector<IntVar*> vars,
00046 const vector<int64> coefficients,
00047 int64 constant);
00048 ConstraintRef MakeSumGreaterOrEqualConstant(const vector<IntVar*> vars,
00049 int64 constant);
00050 ConstraintRef MakeSumLessOrEqualConstant(const vector<IntVar*> vars,
00051 int64 constant);
00052 ConstraintRef MakeSumEqualConstant(const vector<IntVar*> vars,
00053 int64 constant);
00054 ConstraintRef MakeRowConstraint(int64 lb,
00055 const vector<IntVar*> vars,
00056 const vector<int64> coefficients,
00057 int64 ub);
00058 ConstraintRef MakeRowConstraint(int64 lb,
00059 IntVar* const v1,
00060 int64 coeff1,
00061 int64 ub);
00062 ConstraintRef MakeRowConstraint(int64 lb,
00063 IntVar* const v1,
00064 int64 coeff1,
00065 IntVar* const v2,
00066 int64 coeff2,
00067 int64 ub);
00068 ConstraintRef MakeRowConstraint(int64 lb,
00069 IntVar* const v1,
00070 int64 coeff1,
00071 IntVar* const v2,
00072 int64 coeff2,
00073 IntVar* const v3,
00074 int64 coeff3,
00075 int64 ub);
00076 ConstraintRef MakeRowConstraint(int64 lb,
00077 IntVar* const v1,
00078 int64 coeff1,
00079 IntVar* const v2,
00080 int64 coeff2,
00081 IntVar* const v3,
00082 int64 coeff3,
00083 IntVar* const v4,
00084 int64 coeff4,
00085 int64 ub);
00086 ConstraintRef MakeOrConstraint(ConstraintRef left_constraint_index,
00087 ConstraintRef right_constraint_index);
00088
00089 void Add(ConstraintRef constraint_index);
00090 private:
00091 int VarIndex(IntVar* const var);
00092 ConstraintRef Store(ArithmeticConstraint* const constraint);
00093
00094 scoped_ptr<ArithmeticPropagator> propagator_;
00095 hash_map<IntVar*, int> var_indices_;
00096 vector<ArithmeticConstraint*> constraints_;
00097 };
00098
00099 }
00100 #endif // EXAMPLES_GLOBAL_ARITH_H_