Package heart.xtt

Source Code of heart.xtt.Decision

/**
*
*     Copyright 2013-15 by Szymon Bobek, Grzegorz J. Nalepa, Mateusz Ślażyński
*
*
*     This file is part of HeaRTDroid.
*     HeaRTDroid is a rule engine that is based on HeaRT inference engine,
*     XTT2 representation and other concepts developed within the HeKatE project .
*
*     HeaRTDroid 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 3 of the License, or
*     (at your option) any later version.
*
*     HeaRTDroid 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 HeaRTDroid.  If not, see <http://www.gnu.org/licenses/>.
*
**/


package heart.xtt;

import heart.WorkingMemory;
import heart.alsvfd.Expression;
import heart.alsvfd.Value;
import heart.exceptions.AttributeNotRegisteredException;
import heart.exceptions.NotInTheDomainException;

public class Decision {
  protected Attribute attr;
  protected Expression decision;
  protected Expression tail;
 
  /**
   * A variable that contains a name of a Action class
   * that should be triggered with a reflection mechanisms
   * while executing decision.
   */
  protected String action;
 
 
  public Attribute getAttribute() {
    return attr;
  }
 
  public void setAttribute(Attribute attr) {
    this.attr = attr;
  }
 
  public Expression getDecision() {
    return decision;
  }
 
  public void setDecision(Expression decision) {
    this.decision = this.tail =  decision;
  }
 
  public void addExpression(Expression e){
    if(decision == null){
      decision = tail = e;
    }else{
      tail.setExpression(e);
      tail = e;
    }
  }
 
  public boolean execute(WorkingMemory wmthrows UnsupportedOperationException, NotInTheDomainException  {
    try{
      Value newValue = decision.evaluate(wm);
      wm.setAttributeValue(attr, newValue, true);
 
      return true;
    }catch(UnsupportedOperationException e){
      //TODO rethrow with modified message
      throw e;
    }catch(NotInTheDomainException e){
      //TODO: change message
      throw e;
    }catch (SecurityException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
      return false;
    }catch (IllegalArgumentException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
      return false;
    }catch (AttributeNotRegisteredException e) {
      // This will never happen, as the aturoregister option is on
      return false;
    }
  }
 
  @Override
  public String toString() {
    return attr.getName()+" set "+decision;
  }
 
 
}
TOP

Related Classes of heart.xtt.Decision

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.