home Forums # Technical Support Time and Absolute Values? Reply To: Time and Absolute Values?

#970

Hi Fishwaldo,

Thank you for your post and for sharing information about an interesting application of fuzzylite.

I have been thinking about your case since I read about it, and I have one solution.

As for now, I am reluctant to allow the kind of rules you present, but I will surely consider it for another version of fuzzylite in the future.

My solution is to create an InputVariable called Time, besides InputVariable Room, as follows:

InputVariable: Time
  enabled: true
  range: 0.0 23.59
  term: After6pm Function ge(Time, 18)
  term: Before6pm Function lt(Time, 18)
  term: After8pm Function ge(Time, 20)
  term: Before8pm Function lt(Time, 20)
InputVariable: Room
  enabled: true
  range: 0.0 1.0
  term: Occupied Function eq(Room, 1.0)
  term: Empty Function ~eq(Room, 1.0)

Then, the rules would be:

RuleBlock:
  conjunction: AlgebraicProduct
  activation: AlgebraicProduct
  rule: if Room is Occupied and Time is After6pm then AirCond is fullspeed

The changes you need to make in fuzzylite are the following:

In Operation.h, you need to create the following methods,

static scalar gt(scalar a, scalar b); //greater than
static scalar ge(scalar a, scalar b); //greater than or equal to
static scalar eq(scalar a, scalar b); //equal to
static scalar le(scalar a, scalar b); //less than or equal to
static scalar lt(scalar a, scalar b); //less than
static scalar Operation::logicalNot(scalar a) {
        return isEq(a, 1.0) ? 0.0 : 1.0; //Implementation in Operation.cpp
}

and within the methods utilize the respective calls to Op::isGt, Op::isGE, etc.

In Function.cpp, you need to add the new methods as follows:

loadBuiltInFunctions(){
this->functions["gt"] = new BuiltInFunction("gt", &(fl::Op::gt));
this->functions["ge"] = new BuiltInFunction("ge", &(fl::Op::ge));
this->functions["eq"] = new BuiltInFunction("eq", &(fl::Op::eq));
this->functions["le"] = new BuiltInFunction("le", &(fl::Op::le));
this->functions["lt"] = new BuiltInFunction("lt", &(fl::Op::lt));
}
loadOperators(){
int p = 7;
this->operators["!"] = new Operator("!", &(fl::Op::logicalNot), p, 1);
}

As for time, you will have to set the input value for Time manually before processing the Engine.

I have already incorporated the aforementioned changes to fuzzylite v5.0, but I discourage you from using the master repository as it is work in progress and plenty of changes are being made.

Re