Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Sign In with Facebook Sign In with Google Sign In with OpenID

Categories

We have migrated to a new platform! Please note that you will need to reset your password to log in (your credentials are still in-tact though). Please contact lee@programmersheaven.com if you have questions.
Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

Problem in understanding this code

bonnieclydebonnieclyde Posts: 13Member
can someone help me to explain to me how this program work, i need the comments , algorithms and perhaps pseudocode of how this code work.. i attached it as below

#include
#include
#include

#define NUMBEROFRULES 9
#define NUMBEROFINPUTVARIABLES 2
#define NUMBEROFOUTPUTVARIABLES 1
#define NUMBEROFTOTALINPUTSETS 6

struct set{
char name[40];
float minimum;
float maximum;
};

struct variable{
char name[40];
float minimum;
float maximum;
int intervals;
float interval;
int numberSets;
};

struct difusor{
float minimum;
float maximum;
float center;
float var1;
float var2;
float var3;
float var4;
int points;
float interval;
};

struct variable InputVariables[NUMBEROFINPUTVARIABLES];
struct variable OutputVariables[NUMBEROFOUTPUTVARIABLES];
struct set Inputs[NUMBEROFTOTALINPUTSETS];
struct difusor Difusors[NUMBEROFTOTALINPUTSETS];
int Rules[NUMBEROFRULES][NUMBEROFINPUTVARIABLES+NUMBEROFOUTPUTVARIABLES];
float Modifiers[NUMBEROFRULES][NUMBEROFINPUTVARIABLES];

float CenterHeight[NUMBEROFRULES][NUMBEROFOUTPUTVARIABLES];

void FillBasis();
void FillInputVariables();
void FillOutputVariables();
void FillInputs();
void FillDifusors();
void FillRules();
void FillModifiers();

void FillCenterHeight();

void calculate(float *in,float *out);

float combineOutput(int NumberofOutput, float *input);
float combineOutput0(float *input);

float CompositionProperty(int numVar, int numRule, float out);
float DifusorsProperty(float *in);
float ImplicationProperty(int numOut, int numRule,float *in, float out);
float ConsequentProperty(int numOut, int numRule, float out);
float AntecedentProperty(int numRule, float *in);
int activateRule(int numRule);
float DifusorProperty(int numVar, float x);
float InputVariableProperty(int numVar,int numConj, float x);
float OutputVariableProperty(int numVar,int numConj, float x);

int InputsIndex(int numRule,int numVar);
void currentInputs(float *in);

float Implication(float x,float y);
float Composition(float x,float y);
float Conjunction(float x,float y);
float And(float x,float y);

main()
{
float input[NUMBEROFINPUTVARIABLES];
float output[NUMBEROFOUTPUTVARIABLES];
char q='y';
FillBasis();
while(q=='y')
{
int i;
for(i=0;i=Difusors[k].points)
{
inter[k]=1;
}
}
uxab=ImplicationProperty(numVar,numRule,x,out);
uxa=DifusorsProperty(x);
ux=Composition(uxa,uxab);
if(ux>comp)
{
comp=ux;
}
}
}
return comp;
}

float DifusorsProperty(float *in)
{
float uxd;
int j=0;
uxd=DifusorProperty(j,in[j]);
for(j=0;j0.0)
{
uxa=pow(ux,Modifiers[numRule][0]);
}else
{
uxa=1;
}
for(j=1;j0.0)
{
ux=pow(ux,Modifiers[numRule][j]);
}else
{
ux=1;
}
uxa=And(uxa,ux);
}
return uxa;
}

int activateRule(int numRule)
{
int i;
for(i=0;icmx||bmx<cmn)
return 0;
}
return 1;
}
float combineOutput(int NumberofOutput,float *in)
{
float response;
switch(NumberofOutput)
{
case 0 : response=combineOutput0(in);break;
default:response=0;break;
}
return response;
}

float combineOutput0(float *in)
{
int NumberofOutput=0;
float con=0.000000;
float y;
float y1=0;
float y2=0;
float ymax;
int i;
int j;
ymax=OutputVariables[NumberofOutput].minimum;
currentInputs(in);
for(i=0;i<(OutputVariables[NumberofOutput].intervals+1);i++)
{
float con=0.000000;
y=OutputVariables[NumberofOutput].minimum+i*OutputVariables[NumberofOutput].interval;
for(j=0;j<NUMBEROFRULES;j++)
{
float temp;
temp=CompositionProperty(NumberofOutput,j,y);
con=Conjunction(con,temp);
}
y1=y1+y*con;
y2=y2+con;
}
if(fabs(y2)<0.000001)
y2=100000.0;
if(fabs(y1)<0.000001)
y1=0.0;
ymax=y1/y2;
return ymax;
}

void FillInputVariables()
{
strcpy(InputVariables[0].name,"Water Absorption");
InputVariables[0].minimum=0.000000;
InputVariables[0].maximum=5.000000;
InputVariables[0].intervals=20;
InputVariables[0].interval=0.250000;
InputVariables[0].numberSets=3;
strcpy(InputVariables[1].name,"Laundry Weight");
InputVariables[1].minimum=0.000000;
InputVariables[1].maximum=10.000000;
InputVariables[1].intervals=20;
InputVariables[1].interval=0.500000;
InputVariables[1].numberSets=3;
}


/continue on next msg....
Sign In or Register to comment.