// T_1 --> C_1 --> S_1 // T_2 --> C_2 --> S_2 // T_3 --> C_3 --> S_3 // T_1 --> C_1 --> S_New // T_2 --> C_1 // T_3 --> C_1 public void Merge() { Unifier un = new Unifier(new TypeFactory()); DataType dt = null; foreach (StructureType str in structures) { dt = un.Unify(dt, str); } StructureType strNew = (StructureType) dt; eqMin.DataType = strNew; }
public TypedExpressionRewriter(Program prog) { this.prog = prog; this.platform = prog.Platform; this.store = prog.TypeStore; this.globals = prog.Globals; this.compTypes = new DataTypeComparer(); this.tcr = new TypedConstantRewriter(prog); this.m = new ExpressionEmitter(); this.unifier = new Unifier(); }
public override object Execute(Reasoner ts, Unifier un, ITerm[] args) { CheckArguments(args); ts.GetAgent().Abolish((Literal)args[0], un); return(true); }
public void setUp() { parser = new FOLParser(DomainFactory.knowsDomain()); unifier = new Unifier(); theta = CollectionFactory.CreateInsertionOrderedMap <Variable, Term>(); }
public static IEnumerator <Unifier> AllDesires(Circumstance C, Literal l, ITerm intAsTerm, Unifier un) { Trigger teFroml = new Trigger(TEOperator.add, TEType.achieve, l); return(new EnumeratorImpl(C, l, intAsTerm, un, teFroml)); }
public virtual object Execute(Reasoner reasoner, Unifier un, ITerm[] args) { return(false); }
public bool Occurs(string s, object o) { return(Unifier.OccurCheck(new Variable(s), o)); }
public FOLKnowledgeBase(FOLDomain domain, InferenceProcedure inferenceProcedure, Unifier unifier) { this.parser = new FOLParser(new FOLDomain(domain)); this.inferenceProcedure = inferenceProcedure; this.unifier = unifier; // this.substVisitor = new SubstVisitor(); this.variableCollector = new VariableCollector(); this._standardizeApart = new StandardizeApart(variableCollector, substVisitor); this.cnfConverter = new CNFConverter(parser); }
/**************************************************************************/ /* * Returns a clone of this term with changes applied (it replaces variables by their value in the unifier), both operations together. * This double operation should be faster than 'Clone' and then 'Apply'. * u - The unifier */ public virtual ITerm CApply(Unifier u) { // It call Clone specific method, not (ITerm)MemberwiseClone() return((ITerm)Clone()); // Como uso el Clone de C# lo que clono son object que luego hay que castear... }
public object AllDesires(Circumstance circumstance, Literal body, object p, Unifier unifier) { throw new NotImplementedException(); }
public MethodBaseGetCurrentMethodThunkCache() { _cache = new Unifier(); }
public override object Execute(Reasoner ts, Unifier un, ITerm[] args) { CheckArguments(args); return(un.Unifies(args[2], ((IListTerm)args[0]).Difference((IListTerm)args[1]))); }
/* * @Override * public Object execute(TransitionSystem ts, Unifier un, Term[] args) throws Exception { * checkArguments(args); * StringBuffer sb = new StringBuffer(); * for (Term term : args) { * if (!term.isString()) { * continue; * } * StringTerm st = (StringTerm) term; * Matcher matcher = regex.matcher(st.getString()); * * while (matcher.find()) { * * //System.out.println("I found the text \""+matcher.group()+ "\"starting at index "+matcher.start()+ " and ending at index "+matcher.end()); * * String sVar = matcher.group(); * sVar = sVar.substring(2, sVar.length() - 1); //Quita los dos primeros caracteres: # y \, creo que es lo primero que aparece en las variables; y también quita el último: \ * try { * Term t = null; * if (sVar.startsWith("_") && sVar.length() > 1) // deals with unnamed vars, where we cannot use parseTerm * t = new UnnamedVar( Integer.valueOf( sVar.substring(1))); //Le quita la _ al nombre de la variable anónima * else * t = ASSyntax.parseTerm(sVar); //si no ya si que llama al término * * //We use t.apply to evaluate any logical or arithmetic expression in Jason * t = t.capply(un); * matcher.appendReplacement(sb, t.isString() ? ((StringTerm)t).getString() : t.toString()); * } catch (ParseException pe) { * // TODO: handle exception * // TODO: Decide whether or not we should ignore the exception and print the call instead * // Right now, if I get a parse error from ASSyntax, I just print the original escaped * // sequence, so a user can see that his/her expression was problematic * matcher.appendReplacement(sb, "#{"+sVar+"}"); * } * * } * matcher.appendTail(sb); * } * * if (args[args.length - 1].isVar()) { * //Guardar el mensaje todo ello unificado en una sola variable, para depurar * StringTerm stRes = new StringTermImpl(sb.toString()); * return un.unifies(stRes, args[args.length - 1]); * } else { * //Si no hay una variable, lo que quiero es sacar por pantalla todo el mensaje completo * ts.getLogger().info(sb.toString()); //Aquí es por donde se saca por la consola lo que el progrmamador haya querido en su asl * return true; * } * } */ public override object Execute(Reasoner r, Unifier un, ITerm[] args) { CheckArguments(args); StringBuilder sb = new StringBuilder(); foreach (ITerm term in args) { if (!term.IsString()) { continue; } IStringTerm st = (IStringTerm)term; MatchCollection matcher = rx.Matches(st.GetString()); int last = 0; var userBlock = new List <string>(); foreach (Match item in matcher) { //matcher.groups string sVar = item.Groups[0].Value; sVar = sVar.Substring(2, sVar.Length - 1); try { ITerm t = null; if (sVar.StartsWith("_") && sVar.Length > 1) { t = new UnnamedVar(int.Parse(sVar.Substring(1))); } else { t = AsSyntax.AsSyntax.ParseTerm(sVar); } t = t.CApply(un); //Hacer Regex.Replace(sb, t.IsString() ?....) serría una opción para hacerlo más compacto pero no sabemos //matcher.appendReplacement(sb, t.IsString() ? ((IStringTerm)t).GetString() : t.ToString()); if (sVar.Trim().Length > 0) { userBlock.Add(sVar); //No sabemos si esto está bien: el primer Append es para copiar el trozo //no matcheado y el segundo para el trozo que sí sb.Append(st.GetString().Substring(last, item.Index - last)); sb.Append(t.IsString() ? ((IStringTerm)t).GetString() : t.ToString()); } last = item.Index + item.Length; } catch (ParseException pe) { //matcher.appendReplacement(sb, "#{" + sVar + "}"); //Creemos que esto es para añadir el trocito que falta (va a estar mal seguro) sb.Append("#{" + sVar + "}"); } } //matcher.appendTail(sb); sb.Append(st.GetString().Substring(last));//Aquí hay que añadir lo que falta de la cadena original que no matchea } if (args[args.Length - 1].IsVar()) { IStringTerm stRes = new StringTermImpl(sb.ToString()); return(un.Unifies(stRes, args[args.Length - 1])); } else { //r.GetLogger().Info(sb.ToString()); return(true); } }
public void FindDesireAndDrop(Reasoner rs, Literal l, Unifier un) { Trigger g = new Trigger(TEOperator.add, TEType.achieve, l); Circumstance C = rs.GetCircumstance(); Unifier bak = un.Clone(); IEnumerator <Intention> itinit = C.GetRunningIntentionsPlusAtomic(); while (itinit.MoveNext()) { Intention i = itinit.Current; if (DropDesire(i, g, rs, un) > 1) { C.DropRunningIntention(i); un = bak.Clone(); } } // dropping the current intention? DropDesire(C.GetSelectedIntention(), g, rs, un); un = bak.Clone(); //dropping G in Events IEnumerator <Event> ie = C.GetEventsPlusAtomic(); while (ie.MoveNext()) { Event e = ie.Current; //Test in the intention Intention i = e.GetIntention(); int r = DropDesire(i, g, rs, un); if (r > 0) { C.RemoveEvent(e); if (r == 1) { C.ResumeIntention(i); } un = bak.Clone(); } else { //Test in the event Trigger t = e.GetTrigger(); if (i != Intention.emptyInt && !i.IsFinished()) { t = t.Capply(i.Peek().GetUnif()); } if (un.Unifies(g, t)) { DropDesireInEvent(rs, e, i); un = bak.Clone(); } } } //dropping G in Pending Events foreach (string ek in C.GetPendingEvents().Keys) { //Test in the intention Event e = C.GetPendingEvents()[ek]; Intention i = e.GetIntention(); int r = DropDesire(i, g, rs, un); if (r > 0) { C.RemovePendingEvent(ek); if (r == 1) { C.ResumeIntention(i); } un = bak.Clone(); } else { //test in the event Trigger t = e.GetTrigger(); if (i != Intention.emptyInt && !i.IsFinished()) { t = t.Capply(i.Peek().GetUnif()); } if (un.Unifies(g, t)) { DropDesireInEvent(rs, e, i); un = bak.Clone(); } } } //Dropping from pending Actions foreach (ExecuteAction a in C.GetPendingActions().Values) { Intention i = a.GetIntention(); int r = DropDesire(i, g, rs, un); if (r > 0) //i was changed { C.RemovePendingAction(i.GetID()); // remove i from PA if (r == 1) // i must continue running { C.ResumeIntention(i); // and put the intention back in I } // if r > 1, the event was generated and i will be back soon un = bak.Clone(); } } //Dropping from pending intentions foreach (Intention i in C.GetPendingIntentions().Values) { int r = DropDesire(i, g, rs, un); if (r > 0) { C.RemovePendingIntention(i.GetID()); if (r == 1) { C.ResumeIntention(i); } un = bak.Clone(); } } }
public MyRunnable2(Circumstance c, Intention si, string sEvt, bool dropped, bool stopByTimeout, Trigger te, ILogicalFormula formula, ITerm elapsedTimeTerm, Reasoner rs, Unifier un, long startTime) { this.c = c; this.si = si; this.sEvt = sEvt; this.dropped = dropped; this.stopByTimeout = stopByTimeout; this.te = te; this.formula = formula; this.elapsedTimeTerm = elapsedTimeTerm; this.rs = rs; this.un = un; this.startTime = startTime; }
public void Setup() { factory = new TypeFactory(); un = new Unifier(factory); }
public override ITerm[] PrepareArguments(Literal body, Unifier un) { ns = body.GetNS(); return(base.PrepareArguments(body, un)); }
override public ITerm[] PrepareArguments(Literal body, Unifier un) { return(body.GetTermsArray()); }
public override object Execute(Reasoner reasoner, Unifier un, ITerm[] args) { CheckArguments(args); FindDesireAndDrop(reasoner, (Literal)args[0], un); return(true); }
public IdConstant(EvaluationContext ctx, Unifier u) { this.ctx = ctx; this.unifier = u; }
/****** Checks *******/ /* * Returns true only if this term contains the variable t (or unifies with the variable term t?). * t - The variable term * u - The unifier */ public virtual bool HasVar(VarTerm t, Unifier u) { return(false); }
public IdConstant(EvaluationContext ctx, Unifier u, DecompilerEventListener listener) { this.ctx = ctx; this.unifier = u; this.listener = listener; }
public void Setup() { factory = new TypeFactory(); un = new Unifier(factory, null); }
/** * returns all unifications for intentions with some goal */ public static IEnumerator <Unifier> AllIntentions(Circumstance C, Literal l, ITerm intAsTerm, Unifier un) { Trigger g = new Trigger(TEOperator.add, TEType.achieve, l); return(new EnumeratorImpl(C, un, g, intAsTerm)); }
public override object Execute(Reasoner ts, Unifier un, ITerm[] args) { CheckArguments(args); return(args[0].IsGround()); }
public TypeGetTypeMethodThunkCache(TypeDesc owningTypeForThunks) { _owningTypeForThunks = owningTypeForThunks; _cache = new Unifier(this); }
/// <summary> /// Finds the minimal elements, in the partial order induced by unification, of the partial model facts. /// The number of minimal elements gives a lower bound on the number of distinct facts that must appear in an valid model. /// </summary> private void BuildPartialModelLowerBounds() { //// Step 1. Bin facts by head symbol. Term pattern; LinkedList <Term> gbin; Map <Term, MutableTuple <bool> > ngbin; var grdBins = new Map <Symbol, LinkedList <Term> >(Symbol.Compare); //// A term maps to true if it is deleted from the bin. var ngBins = new Map <Symbol, Map <Term, MutableTuple <bool> > >(Symbol.Compare); foreach (var f in Facts.Facts) { pattern = MkPattern(f); if (pattern == f) { Contract.Assert(pattern.Groundness == Groundness.Ground); if (!grdBins.TryFindValue(f.Symbol, out gbin)) { gbin = new LinkedList <Term>(); grdBins.Add(f.Symbol, gbin); } gbin.AddLast(f); } else { Contract.Assert(pattern.Groundness == Groundness.Variable); if (!ngBins.TryFindValue(f.Symbol, out ngbin)) { ngbin = new Map <Term, MutableTuple <bool> >(Term.Compare); ngBins.Add(f.Symbol, ngbin); } if (!ngbin.ContainsKey(pattern)) { ngbin.Add(pattern, new MutableTuple <bool>(false)); } } } //// Step 2. Any non-ground fact that matches with a ground fact is not minimal. Matcher matcher; foreach (var kv in ngBins) { ngbin = kv.Value; if (!grdBins.TryFindValue(kv.Key, out gbin)) { continue; } foreach (var p in ngbin) { matcher = new Matcher(p.Key); foreach (var g in gbin) { if (matcher.TryMatch(g)) { p.Value.Item1 = true; break; } } } PruneBin(ngbin); } //// Step 3. Iteratively compute the minimal elements until a fixpoint is reached. Term mgu; bool changed; LinkedList <Term> newGLBs; foreach (var kv in ngBins) { ngbin = kv.Value; changed = true; while (changed) { changed = false; newGLBs = null; foreach (var p1 in ngbin) { foreach (var p2 in ngbin.GetEnumerable(p1.Key)) { if (p1.Key == p2.Key) { continue; } else if (Unifier.IsUnifiable(p1.Key, p2.Key, x => MkNormalizedVar(Facts.Index, x), out mgu)) { if (mgu != p1.Key) { p1.Value.Item1 = true; } if (mgu != p2.Key) { p2.Value.Item1 = true; } if (mgu != p1.Key && mgu != p2.Key && !ngbin.ContainsKey(mgu)) { changed = true; if (newGLBs == null) { newGLBs = new LinkedList <Term>(); } newGLBs.AddLast(mgu); } } } } PruneBin(ngbin, newGLBs); } } //// Step 4. Create lower bounds Cardinality card; foreach (var kv in ngBins) { grdBins.TryFindValue(kv.Key, out gbin); if (gbin == null) { card = new Cardinality(new BigInteger(kv.Value.Count)); } else { card = new Cardinality(new BigInteger(kv.Value.Count) + new BigInteger(gbin.Count)); } AddConstraint(varMap[(UserSymbol)kv.Key].Item3 >= new CardCnst(card)); } foreach (var kv in grdBins) { if (ngBins.ContainsKey(kv.Key)) { continue; } AddConstraint(varMap[(UserSymbol)kv.Key].Item3 >= new CardCnst(new Cardinality(new BigInteger(kv.Value.Count)))); } }
override public object Execute(Reasoner ts, Unifier un, ITerm[] args) { CheckArguments(args); ts.GetAgent().Buf(ts.GetUserAgArch().Perceive()); return(true); }
public override object Execute(Reasoner ts, Unifier un, ITerm[] args) { CheckArguments(args); return(AllDesires(ts.GetCircumstance(), args[0] as Literal, args.Length == 2 ? args[1] : null, un)); }
public void AddItemWithSize(Address addr, ImageMapItem itemNew) { if (!TryFindItem(addr, out var item)) { throw new ArgumentException(string.Format("Address {0} is not within the image range.", addr)); } // Do not split items with known data. if (!(item.DataType is UnknownType || item.DataType is CodeType)) { return; } long delta = addr - item.Address; Debug.Assert(delta >= 0, "Should have found an item at the supplied address."); if (delta > 0) { int afterOffset = (int)(delta + itemNew.Size); ImageMapItem itemAfter = null; if (item.Size > afterOffset) { itemAfter = new ImageMapItem { Address = addr + itemNew.Size, Size = (uint)(item.Size - afterOffset), DataType = ChopBefore(item.DataType, afterOffset), }; } item.Size = (uint)delta; item.DataType = ChopAfter(item.DataType, (int)delta); // Shrink the existing mofo. Items.Add(addr, itemNew); if (itemAfter != null) { Items.Add(itemAfter.Address, itemAfter); } } else { if (!(item.DataType is UnknownType) && !(item.DataType is CodeType)) { var u = new Unifier(); if (u.AreCompatible(item.DataType, itemNew.DataType)) { item.DataType = u.Unify(item.DataType, itemNew.DataType); } else { throw new NotSupportedException("Haven't handled this case yet."); } } Items.Remove(item.Address); item.Address += itemNew.Size; item.Size -= itemNew.Size; Items.Add(addr, itemNew); if (item.Size > 0 && !Items.ContainsKey(item.Address)) { Items.Add(item.Address, item); } } FireMapChanged(); }
public void CloneTest() { Unifier resultado = un.Clone(); Assert.AreEqual(un, resultado); }
[SetUp] // El @Before de Java public void SetUp() { un = new Unifier(); }
public override object Execute(Reasoner reasoner, Unifier un, ITerm[] args) { //Aqui tengo que coger, de alguna manera, la referencia a la lámpara y encender la luz return(base.Execute(reasoner, un, args)); }