/**
*  When given the attributes of an insect, this ruleset attempts to determine the type of bug. Although this ruleset contains
*  no fuzzy variables at all (!), it demonstrates that the fuzzy inference engine can do simple boolean reasoning. It is not
*  recommended you use it for this purpose, however. To use, change the assertions in the ruleset, re-verify, and re-run.
*/
ruleset Bugs {

  //===============================================
  // VARIABLE Section
  //===============================================
  variables {

    //---------------------------------------------
    // Types of bugs
    //---------------------------------------------
    Categorical BugName = new Categorical(new String[] {"cricket", "ladybug", "japanese beetle", "praying mantis", "spider", "tick"});
    Categorical Family  = new Categorical(new String[] {"arachnid", "insect"});
    Categorical Genus   = new Categorical(new String[] {"beetle", "orthoptera"});

    //---------------------------------------------
    // Bug attributes
    //---------------------------------------------
    Discrete    Antennae  = new Discrete(new Double[] {0, 2});
    Categorical Color     = new Categorical(new String[] {"black", "green", "green and black", "orange and black"});
    Discrete    Legs      = new Discrete(new Double[] {6, 8});
    Categorical LegLength = new Categorical(new String[] {"long", "short"});
    Categorical Shape     = new Categorical(new String[] {"elongated", "round"});
    Categorical Size      = new Categorical(new String[] {"large", "small"});
    Discrete    Wings     = new Discrete(new Double[] {0, 2});

  }


  //===============================================
  // INPUT/OUTPUT Section
  //
  // We don't use any inputs -- we just set
  // arguments using simple assertion rules;
  // see below.
  //
  // We do set the outputs.
  //===============================================
  inputs {};
  outputs {Family, Genus, BugName};

  // Running this ruleset as shipped with ABLE
  // produces the following output:
  //     Variable...<Family>  Value......<insect>
  //     Variable...<Genus>   Value......<beetle>
  //     Variable...<BugName> Value......<ladybug>

  void init() { 
       : setControlParameter(ARL.process, ARL.AlphaCut, 0.01);
  }     

  //===============================================
  // PROCESSING Section
  //===============================================
  void process() using Fuzzy { 

    //---------------------------------------------
    // Given the following attributes,
    // determine the type of bug.
    // You may experiment with changing these.
    //---------------------------------------------
    A01: Antennae  = 0;
    A02: Color     = "orange and black";
    A03: Legs      = 6;
    A04: LegLength = "short";
    A05: Shape     = "round";
    A06: Size      = "small";
    A07: Wings     = 2;

    //---------------------------------------------
    // Rules to determine the type of bug
    //---------------------------------------------
    R08:
      if ( Genus == "beetle"  and
           Color == "orange and black" )
      then
         BugName = "ladybug";

    R09:
      if ( Genus == "beetle"  and
           Color == "green and black" )
      then
         BugName = "japanese beetle";

    R10:
      if ( Genus == "orthoptera"  and
           Color == "black" )
      then
         BugName = "cricket";

    R11:
      if ( Genus == "orthoptera"  and
           Color == "green"       and
           Size  == "large" )
      then
         BugName = "praying mantis";

    //---------------------------------------------
    // Rules to determine the bug's Genus
    //---------------------------------------------
    R12:
      if ( Family == "insect"  and
           Size   == "small"   and
           Shape  == "round" )
      then
         Genus = "beetle";

    R13:
      if ( Family == "insect"  and
           Size   != "small"   and
           Shape  == "elongated" )
      then
         Genus = "orthoptera";

    R14:
      if ( Family    == "arachnid"  and
           LegLength == "long" )
      then
         BugName = "spider";

    R15:
      if ( Family    == "arachnid"  and
           LegLength == "short" )
      then
         BugName = "tick";

    //---------------------------------------------
    // Rules to determine the bug's Family
    //---------------------------------------------
    R16:
      if ( Antennae == 0  and
           Legs     == 8 )
      then
         Family = "arachnid";

    R17:
      if ( Wings == 0 )
      then
         Family = "arachnid";

    R18:
      if ( Antennae == 2  and
           Legs     == 6 )
      then
         Family = "insect";

    R19:
      if ( Wings == 2 )
      then
         Family = "insect";
  }

}