/***************************************************************************
 *   Copyright (C) 2005 by Robot Group Leipzig                             *
 *    martius@informatik.uni-leipzig.de                                    *
 *    fhesse@informatik.uni-leipzig.de                                     *
 *    der@informatik.uni-leipzig.de                                        *
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 *   This program 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 General Public License for more details.                          *
 *                                                                         *
 *   You should have received a copy of the GNU General Public License     *
 *   along with this program; if not, write to the                         *
 *   Free Software Foundation, Inc.,                                       *
 *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
 *                                                                         *
 *   $Log: abstractcontroller.h,v $
 *   Revision 1.19  2008/08/01 14:42:04  guettler
 *   we try the trip to hell! make selforg AVR compatible...good luck (first changes)
 *
 *   Revision 1.18  2008/04/17 14:54:44  martius
 *   randomGen added, which is a random generator with long period and an
 *    internal state. Each Agent has an instance and passed it to the controller
 *    and the wiring. This is good for
 *   a) repeatability on agent basis,
 *   b) parallel execution as done in ode_robots
 *
 *   Revision 1.17  2007/10/12 16:02:17  martius
 *   asserts in init() for sensor and motor number
 *
 *   Revision 1.16  2006/08/04 15:16:13  martius
 *   documentation
 *
 *   Revision 1.15  2006/07/20 17:14:34  martius
 *   removed std namespace from matrix.h
 *   storable interface
 *   abstract model and invertablemodel as superclasses for networks
 *
 *   Revision 1.14  2006/07/14 12:23:57  martius
 *   selforg becomes HEAD
 *
 *   Revision 1.12.6.4  2006/06/25 21:56:06  martius
 *   configureable has name and revision
 *
 *   Revision 1.12.6.3  2006/03/30 12:35:12  martius
 *   documentation updated
 *
 *   Revision 1.12.6.2  2006/01/18 16:48:10  martius
 *   configurables can be stored and reloaded
 *
 *   Revision 1.12.6.1  2006/01/17 16:58:39  martius
 *   loading and storing
 *
 *   Revision 1.12  2005/08/06 20:47:54  martius
 *   Commented
 *
 *   Revision 1.11  2005/08/03 20:28:57  martius
 *   inspectable interface
 *
 *   Revision 1.10  2005/06/21 15:31:11  martius
 *   getSensorNumber and getMotorMumber added controller interface
 *
 *   Revision 1.9  2005/06/20 09:04:16  martius
 *   init function added to controller-interface
 *
 *   Revision 1.8  2005/06/17 10:45:22  martius
 *   GPL added
 *                                                                 *
 ***************************************************************************/
#ifndef __ABSTRACTCONTROLLER_H
#define __ABSTRACTCONTROLLER_H

#ifndef AVR

#include <stdio.h>
#include "configurable.h"
#include "inspectable.h"
#include "storeable.h"
#include "randomgenerator.h"

/**
 * Abstract class (interface) for robot controller.
 * The controller gets a number of input sensor values each timestep
 *  and has to generate a number of output motor values.
 *
 * Interface assumes the following usage:
 *  - init() is called first to initialise the dimension of sensor- and motor space
 *  - each time step
 *     either step() or stepNoLearning() is called to ask the controller for motor values.
 */
class AbstractController : public Configurable, public Inspectable, public Storeable {
public:
  typedef double sensor;
  typedef double motor;

  /// contructor (hint: use $ID$ for revision)
  AbstractController(const std::string& name, const std::string& revision)
    : Configurable(name, revision) {}

  /** initialisation of the controller with the given sensor/ motornumber
      Must be called before use. The random generator is optional.
  */
  virtual void init(int sensornumber, int motornumber, RandGen* randGen = 0)= 0;

  /** @return Number of sensors the controller
      was initialised with or 0 if not initialised */
  virtual int getSensorNumber() const= 0;

  /** @return Number of motors the controller
      was initialised with or 0 if not initialised */
  virtual int getMotorNumber() const= 0;

  /** performs one step (includes learning).
      Calculates motor commands from sensor inputs.
      @param sensors sensors inputs scaled to [-1,1]
      @param sensornumber length of the sensor array
      @param motors motors outputs. MUST have enough space for motor values!
      @param motornumber length of the provided motor array
  */
  virtual void step(const sensor* sensors, int sensornumber,
                    motor* motors, int motornumber)= 0;
  /** performs one step without learning.
      @see step
  */
  virtual void stepNoLearning(const sensor* , int number_sensors,
                              motor* , int number_motors)= 0;

};

#else /* AVR */

#include "configurable.h"
#include "inspectable.h"
#include "storeable.h"
#include "randomgenerator.h"

/**
 * Abstract class (interface) for robot controller.
 * The controller gets a number of input sensor values each timestep
 *  and has to generate a number of output motor values.
 *
 * Interface assumes the following usage:
 *  - init() is called first to initialise the dimension of sensor- and motor space
 *  - each time step
 *     either step() or stepNoLearning() is called to ask the controller for motor values.
 */
class AbstractController : public Configurable, public Inspectable, public Storeable {
public:
  typedef double sensor;
  typedef double motor;

  /// contructor (hint: use $ID$ for revision)
  AbstractController(const std::string& name, const std::string& revision)
    : Configurable(name, revision) {}

  /** initialisation of the controller with the given sensor/ motornumber
      Must be called before use. The random generator is optional.
  */
  virtual void init(int sensornumber, int motornumber, RandGen* randGen = 0)= 0;

  /** @return Number of sensors the controller
      was initialised with or 0 if not initialised */
  virtual int getSensorNumber() const= 0;

  /** @return Number of motors the controller
      was initialised with or 0 if not initialised */
  virtual int getMotorNumber() const= 0;

  /** performs one step (includes learning).
      Calculates motor commands from sensor inputs.
      @param sensors sensors inputs scaled to [-1,1]
      @param sensornumber length of the sensor array
      @param motors motors outputs. MUST have enough space for motor values!
      @param motornumber length of the provided motor array
  */
  virtual void step(const sensor* sensors, int sensornumber,
                    motor* motors, int motornumber)= 0;
  /** performs one step without learning.
      @see step
  */
  virtual void stepNoLearning(const sensor* , int number_sensors,
                              motor* , int number_motors)= 0;

};

#endif /* !AVR */

#endif
