/****************************************************************************
 * This file was derived from the CNCL library by the Pablo research group.
 *
 * The complete CNCL library is available at:
 *       http://www.comnets.rwth-aachen.de/doc/cncl.html
 *
 * The CNCL copyright notice is included here:
 *
 * |_|_|_  |_|_    |_    |_|_|_  |_               C O M M U N I C A T I O N
 *|_       |_  |_  |_  |_        |_                         N E T W O R K S
 *|_       |_  |_  |_  |_        |_                               C L A S S
 * |_|_|_  |_    |_|_    |_|_|_  |_|_|_|_                     L I B R A R Y
 *
 *
 *
 * Copyright (C) 1992-1998   Communication Networks
 *                           Aachen University of Technology
 *                           D-52056 Aachen
 *                           Germany
 *                           Email: cncl-adm@comnets.rwth-aachen.de
 *
 *
 * This library is free  software; you can  redistribute it and/or modify
 * it  under   the terms  of the GNU   Library  General Public License as
 * published by the  Free Software Foundation;  either  version 2 of  the
 * License, or  (at  your option)  any  later  version.  This  library is
 * distributed  in the  hope  that  it  will  be useful,  but WITHOUT ANY
 * WARRANTY;  without even the   implied  warranty of MERCHANTABILITY  or
 * FITNESS FOR A PARTICULAR PURPOSE.   See the GNU Library General Public
 * Library General Public License along with  this library; if not, write
 * to the Free Software Foundation,  675  Mass Ave, Cambridge, MA  02139,
 * USA.
 ****************************************************************************/

//   -*- C++ -*-
/*****************************************************************************
 *
 * Class: FlFVar --- Fuzzy variable
 *
 *****************************************************************************/

#ifndef __FlFVar_h
#define __FlFVar_h


#include <FlNamed.h>                // Base class
#include <FlFSet.h>
#include <FlArrayObject.h>


/*
 * The class FlFVar
 */

class FlFVar : public FlNamed
{
  public:
    double set_value(double x);                 // Set/get value
    double value(double x);
    double get_value()         const;
    double value()             const;

    FlFSet *set_fuzzy_value(FlFSet *x);         // Set/get fuzzy value
    FlFSet *fuzzy_value(FlFSet *x);
    FlFSet *get_fuzzy_value()   const;
    FlFSet *fuzzy_value()       const;

    double get_xmin()          const;           // Get xmin/xmax
    double get_xmax()          const;
    double xmin()              const;
    double xmax()              const;

    // Access to array of linguistic values
    void add_value_set(FlFSet &fset);           // Add fuzzy set
    void add_value_set(FlFSet *fset);
    void add_value_set(int i, FlFSet &fset);        
    void add_value_set(int i, FlFSet *fset);

    FlFSet *get_value_set(int i);               // Get fuzzy set [i]
    double get_membership(int i);               // Get membership for fuzzy set [i]
                                                // and current value of fuzzy var
   
    FlArrayObject *get_varsets();               // Get all fuzzy sets for this variable

    // Debug functions
    void print_membership();                    // Compute membership for each fuzzy
                                                // and print results
  private:
    double        varvalue;                     // Current value
    FlFSet       *varfvalue;                    // Current fuzzy value
    double        varxmin, varxmax;             // value range
    FlArrayObject varsets;                      // Affiliated fuzzy sets

    /***** Constructors ******************************************************/
  public:
    FlFVar();                //  constructor
    FlFVar(double min, double max);
    FlFVar(FlStringR xname, double min=0, double max=1);

    void init(FlStringR xname, double min, double max);
    
    // Print/debug output
    void generatePlotFiles(int steps = 10, FlStringR tag = "");
    void plot(int steps = 10, FlStringR tag = "");
    virtual void print(ostream &strm = cout) const;
    virtual void dump (ostream &strm = cout) const;
};


#endif /**__FlFVar_h**/

