#include "TestModel.h" using namespace Fuzzy; // test model definition TestModel::TestModel(string file): Model(file), angle(-1), velocity(-1), speed(-1) { // fuzzy variables definitions created by the base class (Fuzzy::Model) // Input/Output methods; Input/Output arguments are refs // to double scalar variables Var& Angle = Input(angle); Var& Vlcty = Input(velocity); Var& Speed = Output(speed); // membership functions definitions created by fuzzy variables // Term method; Term method takes curve name as an argument; // cureve names are defined in the Fuzzy::Model curve definition // file MemFun& AngleNegHigh = Angle.Term("AngleNegHigh"); MemFun& AngleNegLow = Angle.Term("AngleNegLow"); MemFun& AngleZero = Angle.Term("AngleZero"); MemFun& AnglePosLow = Angle.Term("AnglePosLow"); MemFun& AnglePosHigh = Angle.Term("AnglePosHigh"); MemFun& VlctyNegHigh = Vlcty.Term("VelocityNegHigh"); MemFun& VlctyNegLow = Vlcty.Term("VelocityNegLow"); MemFun& VlctyZero = Vlcty.Term("VelocityZero"); MemFun& VlctyPosLow = Vlcty.Term("VelocityPosLow"); MemFun& VlctyPosHigh = Vlcty.Term("VelocityPosHigh"); MemFun& SpeedNegHigh = Speed.Term("AngleNegHigh"); MemFun& SpeedNegLow = Speed.Term("AngleNegLow"); MemFun& SpeedZero = Speed.Term("AngleZero"); MemFun& SpeedPosLow = Speed.Term("AnglePosLow"); MemFun& SpeedPosHigh = Speed.Term("AnglePosHigh"); // these are the model rules; syntax is pretty strightforward; // rules look like operator >> where lhs is the condition and // rhs is the conclusion; // lhs and rhs have to be in parens if they contain more then // one term because of the c++ operators precedence rules; // conclusion may be a comma separated list of output terms // in parens ((AngleZero and VlctyZero)or(AnglePosLow and VlctyNegLow)or(AngleNegLow and VlctyPosLow)) >> SpeedZero; ((AngleZero and VlctyNegLow)or(AngleNegLow and VlctyZero)) >> SpeedNegLow; ((AnglePosLow and VlctyZero)or(AngleZero and VlctyPosLow)) >> SpeedPosLow; ((AngleZero and VlctyNegHigh)or(AngleNegHigh and VlctyZero)) >> SpeedNegHigh; ((AnglePosHigh and VlctyZero)or(AngleZero and VlctyPosHigh)) >> SpeedPosHigh; } TestModel::~TestModel() { } void TestModel::run(double a, double v, double &s) { // we assign scalar variables to class members angle = a; velocity = v; speed = s; // then run the model // it should be pretty fast as it all designed to preallocate // all the needed large objects in the model constructor Model::run(); // and assign the values of output variables s = speed; }