public double Solve() { if (value == null) //try to solve without unifier { CApply(null); } if (value == null) { throw new Exception("Error evaluating " + this + "." + (IsGround() ? "" : " It is not ground.")); } else { return(value.Solve()); } }
public override bool Equals(object o) { if (o == this) { return(true); } if (o != null && (o.GetType() == typeof(ITerm)) && (((ITerm)o).IsNumeric() && ((ITerm)o).IsArithExpr())) { INumberTerm st = o as INumberTerm; try { return(Solve() == st.Solve()); } catch (Exception e) { } } return(false); }
override public object Execute(Reasoner ts, Unifier un, ITerm[] args) { CheckArguments(args); long timeout = -1; Trigger te = null; ILogicalFormula f = null; ITerm elapsedTime = null; if (args[0].IsNumeric()) { // time in milliseconds INumberTerm time = (INumberTerm)args[0]; timeout = (long)time.Solve(); } else { te = Trigger.TryToGetTrigger(args[0]); // wait for event if (te == null && args[0].GetType() == typeof(ILogicalFormula)) { // wait for an expression to become true f = (ILogicalFormula)args[0]; if (ts.GetAgent().Believes(f, un)) { // if the agent already believes f // place current intention back in I, since .wait usually does not do that Intention si = ts.GetCircumstance().GetSelectedIntention(); si.Peek().RemoveCurrentStep(); ts.GetCircumstance().AddRunningIntention(si); return(true); } } if (args.Length >= 2) { timeout = (long)((INumberTerm)args[1]).Solve(); } if (args.Length == 3) { elapsedTime = args[2]; } } new WaitEvent(te, f, un, ts, timeout, elapsedTime); return(true); }
public static object TermToObject(ITerm t) { if (t.IsAtom()) { Atom t2 = (Atom)t; if (t2.Equals(Literal.LTrue)) { return(true); //?? Boolean.TRUE } else if (t2.Equals(Literal.LFalse)) { return(false); //?? Boolean.FALSE } else { return(t2.ToString()); } } else if (t.IsNumeric()) { INumberTerm nt = (INumberTerm)t; double d = 0; try { d = nt.Solve(); } catch (NoValueException e) { //e.printStackTrace(); } if (((byte)d) == d) { return((byte)d); } else if (((int)d) == d) { return((int)d); } else if (((float)d) == d) { return((float)d); } else if (((long)d) == d) { return((long)d); } else { return(d); } } else if (t.IsString()) { return(((IStringTerm)t).GetString()); } else if (t.IsList()) { List <object> list = new List <object>(); foreach (ITerm t1 in (IListTerm)t) { list.Add(TermToObject(t1)); } return(list); } else if (t.GetType() == typeof(IObjectTerm)) { return(((IObjectTerm)t).GetObject()); } else { return(t.ToString()); } }