• Facebook
  • Twitter
  • Reddit
  • StumbleUpon
  • Digg
  • email

#------------------------------------------------------------------------------
# Copyright (C) 2007 Richard W. Lincoln
#
# 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; version 2 dated June, 1991.
#
# This software is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANDABILITY 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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
#------------------------------------------------------------------------------
 
"""
Elementary action : increment, decrement or do not change the contraction
level of a Muscle.
 
"""
 
#------------------------------------------------------------------------------
#  Imports:
#------------------------------------------------------------------------------
 
# Standard library imports.
import logging
 
# Enthought library imports
from enthought.traits.api import Int, Instance, This
 
# Pyqle imports:
from pyqle.environment.abstract_action import AbstractAction
 
# Setup a logger for this module.
logger = logging.getLogger(__name__)
 
#------------------------------------------------------------------------------
#  "MuscleAction" class:
#------------------------------------------------------------------------------
 
class MuscleAction(AbstractAction):
    """
    Elementary action : increment, decrement or do not change the contraction
    level of a Muscle.
 
    """
 
    type_move = Int(0)
 
    CONTRACT = Instance(This, This(1))
 
    DECONTRACT = Instance(This, This(-1))
 
    STILL = Instance(This, This(0))
 
 
    def __eq__(self, o):
        if not isinstance(o, (MuscleAction)):
            return False
        a = o
        return (self.typeMove == a.typeMove)
 
 
    def get_value(self):
        return self.type_move
 
 
    def copy(self):
        if self.type_move == 0:
            return self.STILL
        elif self.type_move == 1:
            return self.CONTRACT
        elif self.type_move == -1:
            return self.DECONTRACT
        else:
            return
 
 
    def hash_code(self):
        return self.type_move + 1
 
 
    def nn_coding_size(self):
        """
        One among 3 coding
 
        """
 
        return 3
 
 
    def nn_coding(self):
        code = [float() for __idx0 in range(3)]
        code[self.typeMove + 1] = 1.0
        return code
 
 
    def to_string(self):
        return self.type_move + ""
 
# EOF -------------------------------------------------------------------------