Ejemplo n.º 1
0
 public override void addActivation(IActivation act)
 {
     if (act is LinkedActivation)
     {
         LinkedActivation newact = (LinkedActivation) act;
         if (lazy)
         {
             if (count == 0)
             {
                 first = newact;
                 last = newact;
             }
             else
             {
                 last.Next = newact;
                 last = newact;
             }
             count++;
         }
         else
         {
             if (count > 0)
             {
                 quickSort(newact);
             }
             else if (count == 0)
             {
                 first = newact;
                 last = newact;
             }
             count++;
         }
     }
 }
Ejemplo n.º 2
0
 /// <param name="">facts
 /// </param>
 /// <param name="">engine
 /// 
 /// </param>
 public override void assertFacts(Index inx, Rete engine, IWorkingMemory mem)
 {
     long time = (DateTime.Now.Ticks - 621355968000000000)/10000;
     if (theRule.ExpirationDate > 0 && time > theRule.EffectiveDate && time < theRule.ExpirationDate)
     {
         LinkedActivation act = new LinkedActivation(theRule, inx);
         act.TerminalNode = this;
         // fire the activation immediately
         engine.fireActivation(act);
     }
 }
Ejemplo n.º 3
0
 /// <summary> The implementation checks to see if the rule is active before it tries to
 /// assert the fact. It checks in the following order.
 /// 1. is the expiration date greater than zero
 /// 2. is the current time > the effective date
 /// 3. is the current time the expiration date
 /// </summary>
 /// <param name="">facts
 /// </param>
 /// <param name="">engine
 /// 
 /// </param>
 public override void assertFacts(Index inx, Rete engine, IWorkingMemory mem)
 {
     long time = (DateTime.Now.Ticks - 621355968000000000)/10000;
     if (theRule.ExpirationDate > 0 && time > theRule.EffectiveDate && time < theRule.ExpirationDate)
     {
         LinkedActivation act = new LinkedActivation(theRule, inx);
         act.TerminalNode = this;
         IGenericMap<Object, Object> tmem = (IGenericMap<Object, Object>) mem.getTerminalMemory(this);
         tmem.Put(act.Index, act);
         // Add the activation to the current module's activation list.
         engine.Agenda.addActivation(act);
     }
 }
Ejemplo n.º 4
0
 /// <summary> Method will call checkFacts() first to make sure none of the facts have
 /// expired. An activation is only created if the facts are valid.
 /// </summary>
 /// <param name="">facts
 /// </param>
 /// <param name="">engine
 /// 
 /// </param>
 public override void assertFacts(Index inx, Rete engine, IWorkingMemory mem)
 {
     // first check the facts and make sure they didn't expire
     if (checkFacts(inx, engine, mem))
     {
         LinkedActivation act = new LinkedActivation(theRule, inx);
         act.TerminalNode = this;
         if (temporal)
         {
             engine.fireActivation(act);
         }
         else
         {
             IGenericMap<Object, Object> tmem = (IGenericMap<Object, Object>) mem.getTerminalMemory(this);
             tmem.Put(inx, act);
             // Add the activation to the current module's activation list.
             engine.Agenda.addActivation(act);
         }
     }
 }
Ejemplo n.º 5
0
 /// <summary>
 /// method will loop for the given count and return the item before it.
 /// for example:
 /// 1
 /// 2
 /// 3
 /// 4
 /// 5
 /// 6
 /// If I pass a count of 2 and item #6. it will return #4.
 /// </summary>
 /// <param name="count">The count.</param>
 /// <param name="start">The start.</param>
 /// <returns></returns>
 protected internal virtual LinkedActivation goUp(int count, LinkedActivation start)
 {
     LinkedActivation rt = start;
     for (int idx = 0; idx < count; idx++)
     {
         rt = rt.Previous;
     }
     return rt;
 }
Ejemplo n.º 6
0
 /// <summary>
 /// method will loop for the given count and return the item after it.
 /// for example:
 /// 1
 /// 2
 /// 3
 /// 4
 /// 5
 /// 6
 /// If I pass a count of 2 and item #1. it will return #3.
 /// </summary>
 /// <param name="count">The count.</param>
 /// <param name="start">The start.</param>
 /// <returns></returns>
 protected internal virtual LinkedActivation goDown(int count, LinkedActivation start)
 {
     LinkedActivation rt = start;
     for (int idx = 0; idx < count; idx++)
     {
         rt = rt.Next;
     }
     return rt;
 }
Ejemplo n.º 7
0
 /// <summary> removeActivation will check to see if the activation is
 /// the first or last before removing it.
 /// </summary>
 public override IActivation removeActivation(IActivation act)
 {
     if (act is LinkedActivation)
     {
         LinkedActivation lact = (LinkedActivation) act;
         if (first == lact)
         {
             first = lact.Next;
         }
         if (last == lact)
         {
             last = lact.Previous;
         }
         count--;
         lact.remove();
     }
     return act;
 }
Ejemplo n.º 8
0
 /// <summary>
 /// the sort method uses binary search to find the correct insertion
 /// point for the new activation. It's much faster than the brute
 /// force method.
 /// </summary>
 /// <param name="newact">The newact.</param>
 public virtual void quickSort(LinkedActivation newact)
 {
     if (stratey.compare(newact, last) >= 0)
     {
         // the new activation has a higher salience than the last, which means
         // it should become the bottom activation
         last.Next = newact;
         last = newact;
     }
     else if (stratey.compare(newact, first) < 0)
     {
         // the new activation has a salience lower than the first, which means
         // it should become the top activation
         newact.Next = first;
         first = newact;
     }
     else
     {
         // this means the new activation goes in the middle some where
         int counter = count/2;
         LinkedActivation cur = goUp(counter, last);
         bool added = false;
         while (!added)
         {
             if (counter <= 1)
             {
                 // Add the activation
                 if (stratey.compare(newact, cur) < 0)
                 {
                     // if the new activation is lower sailence than the current,
                     // we Add it before the current (aka above)
                     newact.Previous = cur.Previous;
                     newact.Next = cur;
                 }
                 else
                 {
                     // the new activation is higher salience than the current
                     // therefore we Add it after (aka below)
                     newact.Next = cur.Next;
                     newact.Previous = cur;
                 }
                 added = true;
             }
             else if (stratey.compare(newact, cur) >= 0)
             {
                 // the new activation is of greater salience down half again
                 counter = counter/2;
                 cur = goDown(counter, cur);
             }
             else
             {
                 // the new activation is of lower salience, up half again
                 counter = counter/2;
                 cur = goUp(counter, cur);
             }
         }
     }
 }
Ejemplo n.º 9
0
 public override IActivation nextActivation()
 {
     if (lazy)
     {
         if (count == 0)
         {
             return null;
         }
         else
         {
             LinkedActivation left = last;
             LinkedActivation right = last.Previous;
             while (right != null)
             {
                 if (stratey.compare(left, right) < 1)
                 {
                     left = right;
                 }
                 right = right.Previous;
             }
             if (left == first)
             {
                 first = left.Next;
             }
             else if (left == last)
             {
                 last = left.Previous;
             }
             left.remove();
             count--;
             return left;
         }
     }
     else
     {
         if (count > 1)
         {
             LinkedActivation r = last;
             last = r.Previous;
             count--;
             r.remove();
             return r;
         }
         else if (count == 1)
         {
             LinkedActivation r = last;
             last = null;
             first = null;
             count--;
             return r;
         }
         else
         {
             return null;
         }
     }
 }
Ejemplo n.º 10
0
 /// <summary> Iterate over the Creshendo.rete.util.LinkedList and null the references to previous
 /// and Current in the LinkedActivation
 /// </summary>
 public override void clear()
 {
     while (first != null)
     {
         LinkedActivation la = first;
         first = la.Next;
         la.remove();
     }
     last = null;
     count = 0;
 }