Crevice  0.1
 All Classes Functions Variables Pages
Term.h
1 /*
2  * File: Term.h
3  *
4  * Copyright 2012 Heinrich Schuchardt <xypron.glpk@gmx.de>
5  *
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  */
18 
19 #ifndef TERM_H
20 #define TERM_H
21 
22 #include <string>
23 #include <iostream>
24 #include <vector>
25 #include <set>
26 #include "ProblemMismatchException.h"
27 #include "TermValue.h"
28 #include "TermValueComperator.h"
29 
30 class Problem;
31 class Term;
32 class TermVariable;
33 
34 typedef std::vector<Term*> TermPointerVector;
35 typedef std::vector<double> DoubleVector;
36 typedef std::set<TermValue, TermValueComperator> TermValueSet;
37 typedef std::vector<TermVariable*> TermVariablePointerVector;
38 
42 class Term {
43  friend class Problem;
44 public:
45  static const int INVALID_INDEX = -1;
46  virtual Term* differentiate(TermVariable* variable) throw
48  double evaluate(
49  const DoubleVector* variableValues);
50  double evaluate(
51  const DoubleVector* variableValues,
52  TermValueSet* termValues);
53  virtual Problem* getProblem() const;
54  const int getTermIndex();
55  virtual bool less(const Term* term) const;
56  virtual std::string toString() const;
57 protected:
58  virtual double eval(
59  const DoubleVector* variableValues,
60  TermValueSet* termValues);
61  void setTermIndex(const int termIndex);
62  Term(Problem* problem);
63  virtual ~Term();
64 private:
65  Problem* problem_;
66  int termIndex_;
67 };
68 
69 std::ostream& operator<<(std::ostream& outs, const Term* term);
70 #endif /* TERM_H */
71