00001
00002
00003
00004 #ifndef FITYK__VAR__H__
00005 #define FITYK__VAR__H__
00006
00007 #include "common.h"
00008 #include "vm.h"
00009
00010 struct OpTree;
00011 class Variable;
00012 class Function;
00013 class Sum;
00014
00015 class VariableUser
00016 {
00017 public:
00018 const std::string name;
00019 const std::string prefix;
00020
00021 VariableUser(const std::string &name_, std::string const &prefix_,
00022 const std::vector<std::string> &vars = std::vector<std::string>())
00023 : name(name_), prefix(prefix_), varnames(vars) {}
00024 virtual ~VariableUser() {}
00025 bool is_auto_delete() const { return name.size() > 0 && name[0] == '_'; }
00026
00027 bool is_dependent_on(int idx, const std::vector<Variable*> &variables)const;
00028 bool is_directly_dependent_on(int idx) const
00029 { return contains_element(var_idx, idx); }
00030
00031 virtual void set_var_idx(const std::vector<Variable*>& variables);
00032 int get_var_idx(int n) const
00033 { assert(n >= 0 && n < size(var_idx)); return var_idx[n]; }
00034 int get_max_var_idx();
00035 int get_vars_count() const { return varnames.size(); }
00036 const std::vector<std::string>& get_varnames() const { return varnames; }
00037 std::string get_var_name(int n) const
00038 { assert(n >= 0 && n < size(varnames)); return varnames[n]; }
00039 void substitute_param(int n, const std::string &new_p)
00040 { assert(n >= 0 && n < size(varnames)); varnames[n] = new_p; }
00041 std::string get_debug_idx_info() const;
00042
00043 protected:
00044 std::vector<std::string> varnames;
00045
00046
00047 std::vector<int> var_idx;
00048 };
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063 class Variable : public VariableUser
00064 {
00065 public:
00066 RealRange domain;
00067
00068 struct ParMult { int p; realt mult; };
00069 Variable(const std::string &name_, int nr_);
00070 Variable(const std::string &name_, const std::vector<std::string> &vars_,
00071 const std::vector<OpTree*> &op_trees_);
00072 ~Variable();
00073 void recalculate(const std::vector<Variable*> &variables,
00074 const std::vector<realt> ¶meters);
00075
00076 int get_nr() const { return nr_; };
00077 void erased_parameter(int k);
00078 realt get_value() const { return value_; };
00079 std::string get_formula(const std::vector<realt> ¶meters) const;
00080 bool is_visible() const { return true; }
00081 void set_var_idx(const std::vector<Variable*> &variables);
00082 const std::vector<ParMult>& recursive_derivatives() const
00083 { return recursive_derivatives_; }
00084 bool is_simple() const { return nr_ != -1; }
00085 bool is_constant() const;
00086
00087 std::vector<OpTree*> const& get_op_trees() const { return op_trees_; }
00088 void set_original(const Variable* orig) { assert(nr_==-2); original_=orig; }
00089 realt get_derivative(int n) const { return derivatives_[n]; }
00090
00091 private:
00092 int nr_;
00093 realt value_;
00094 std::vector<realt> derivatives_;
00095 std::vector<ParMult> recursive_derivatives_;
00096 std::vector<OpTree*> op_trees_;
00097 VMData vm_;
00098 Variable const* original_;
00099 };
00100
00101 #endif