/*
 * 	FuzzyRule.h
 *
 * 	This class is used to stock FuzzyRule.
 *
 *	Date 20/01/06
 *
 *	Copyright Piquier Production
 *
 *	Author : Dave Studio
 *
 */

#ifndef FUZZYRULE_H
#define FUZZYRULE_H

#include <vector>
#include <stdio.h>
#include "FuzzyValueName.h"
#include "Converter.h"
#include "Operator.h"
#include "FuzzyValue.h"



class FuzzyRule{

private:

	FuzzyValue result;

	/*
	 * List of all fuzzy rules used in the rule result inclued
	 */
	std::vector<FuzzyValue*> listFuzzyValues;

	/*
	 * List of operator used in the rule. They are entered in the order of appearance.
	 * The last have to be an implication.
	 */
	std::vector<Operator*> listOperators;

public:

	/*
	 *Constructor
	 */
	FuzzyRule(void);

	/*
	 *Constructor : initialise the list of fuzzy values and of operator 
	 */
	FuzzyRule(FuzzyValue* fuzzyValueData, Operator* ope, FuzzyValue* result);

	/**
	 *Constructor : initialise the lists of fuzzy values and of operator
	 * 				 take in order, FuzzyValue, Operator, 
	 * 				 				FuzzyValue, Operator,
	 * 								FuzzyValue
	 *
	 *Example : FuzzyRule(faible, et, peuNombreux, implicate, flee);
	 */
	FuzzyRule(FuzzyValue* fuzzyValueData1, Operator* ope1,
			         FuzzyValue* fuzzyValueData2, Operator* ope2, 
			         FuzzyValue* result);

	/**
	 * Constructor : initialise the lists of fuzzy values and of operator
	 * 				 take in order, FuzzyValue, Operator, 
	 * 				 				FuzzyValue, Operator,
	 * 				 				FuzzyValue, Operator,
	 * 								FuzzyValue
	 *
	 * Example : FuzzyRule(faible, et, peuNombreux, et, ennemisVisibles, implicate, flee);
	 */
	FuzzyRule(FuzzyValue* fuzzyValueData1, Operator* ope1,
					 FuzzyValue* fuzzyValueData2, Operator* ope2, 
					 FuzzyValue* fuzzyValueData3, Operator* ope3, 
					 FuzzyValue* result);

	/**
	 *Constructor : initialise the list of fuzzy values and of operator 
	 */
	FuzzyRule(std::vector<FuzzyValue*>* lfv, std::vector<Operator*>* lo);
	
	/**
	 *getResult : Return the FuzzyValue result of the FuzzyRule.
	 * 
	 *@param void
	 * 
	 *@return FuzzyValue : The FuzzyValue result of the FuzzyRule after
	 * 					   evaluation
	 *
	 *@pre : The fuzzyRule have to be evaluated before using this fonction.
	 *
	 */
	FuzzyValue getResult();

	/**
	 *evaluate : Evaluate the fuzzy rule and set the result variable
	 * 			  to the value result of the FuzzyRule
	 * 			  
	 *@param : no parameter
	 * 
	 *@return : => FuzzyValue : The FuzzyValue result of the evaluation of
	 * 							 the FuzzyRule. Its name is the name of the
	 * 							 the last FuzzyValue which is the FuzzyValue
	 * 						     result.
	 * 
	 *@pre : The last FuzzyValue is the name of the FuzzyValue result
	 * 
	 *@post : The result is a new FuzzyValue. The fonction result() 
	 * 		   can be used after this fonction.
	 * 
	 */
	void evaluate() ;

	/**
	 *toString : Give the representation of the FuzzyRule in String.
	 * 
	 *Description : The representation of a FuzzyRule is like this :
	 * 				 _ "or" is the operator Or.
	 * 				 _ "and" is the operator And.
	 * 				 _ "=>" is the operator implication.
	 * 				 _ "myFuzzyValue(itsValue)" is the FuzzyValue represented
	 * 				   by it value and it must be a float between 0 and 1. It
	 * 				   can be -1, it means that the FuzzyValue is not evaluated. 
	 * 
	 *@param void
	 * 
	 *@return String : The representation of the FuzzyRule.
	 * 
	 *@pre : The FuzzyValue must be initialysed. If the value of the result
	 * 		 is -1, it means the fuzzyRule is not evaluated.
	 * 
	 */
	std::string toString();

	/**
	 *update : update all FuzzyValues in the FuzzyRule
	 * 
	 *@param void
	 * 
	 *@return void
	 * 
	 */
	void update();


public:
	~FuzzyRule(void);
};

#endif