openModeller  Version 1.5.0
rules_negrange.cpp
Go to the documentation of this file.
1 
36 #include <openmodeller/Random.hh>
37 #include <math.h>
38 #include <string.h>
39 
40 #include <openmodeller/Log.hh>
41 
42 #include "rules_negrange.hh"
43 
44 
45 // ==========================================================================
46 // NegatedRangeRule implelentation
47 // ==========================================================================
49  RangeRule()
50 {}
51 
53  RangeRule(numGenes)
54 { }
55 
56 NegatedRangeRule::NegatedRangeRule(Scalar prediction, int numGenes,
57  const Sample& chrom1, const Sample& chrom2,
58  const double * performances) :
59  RangeRule(prediction, numGenes, chrom1, chrom2, performances)
60 {}
61 
62 // ==========================================================================
64 
65 // ==========================================================================
66 bool NegatedRangeRule::applies(const Sample& sample) const
67 {
68  int i;
69 
70  // visit each of the genes
71  for (i = 0; i < _numGenes; i++)
72  {
73  if (!(equalEps(_chrom1[i], -1.0) && equalEps(_chrom2[i], +1.0)))
74  if (!between(sample[i], _chrom1[i], _chrom2[i]))
75  return true;
76  }
77 
78  return false;
79 }
80 
81 // ==========================================================================
82 int NegatedRangeRule::getStrength(const Sample& sample) const
83 {
84  int strength, neg_strength;
85 
86  strength = RangeRule::getStrength(sample);
87  neg_strength = 1 - strength;
88 
89  return neg_strength;
90 }
91 
92 // ==========================================================================
94 {
95  Log::instance()->info( "Negated: " );
96  GarpRule::log();
97 }
98 
99 // ==========================================================================
virtual ~NegatedRangeRule()
Definition: Rule.cpp:622
virtual void log()
Definition: rules_base.cpp:469
double Scalar
Type of map values.
Definition: om_defs.hh:39
static Log * instance()
Returns the instance pointer, creating the object on the first call.
Definition: Log.cpp:45
virtual double getStrength(EnvCell *cell)
Definition: Rule.cpp:650
Sample _chrom1
BYTE vector containing the genes (representation of the variables in a Genetic Algorithm.
Definition: rules_base.hh:180
virtual double getStrength(EnvCell *cell)
Definition: Rule.cpp:588
virtual bool applies(const Sample &sample) const
bool between(double value, double min, double max)
Definition: rules_base.cpp:67
int _numGenes
Number of genes stored by the rule.
Definition: rules_base.hh:185
bool equalEps(double v1, double v2)
Definition: rules_base.cpp:62
Sample _chrom2
Definition: rules_base.hh:181
void info(const char *format,...)
'Info' level.
Definition: Log.cpp:256
Definition: Sample.hh:25