当前位置: 首页>>代码示例>>Java>>正文


Java Unifier.clone方法代码示例

本文整理汇总了Java中jason.asSemantics.Unifier.clone方法的典型用法代码示例。如果您正苦于以下问题:Java Unifier.clone方法的具体用法?Java Unifier.clone怎么用?Java Unifier.clone使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在jason.asSemantics.Unifier的用法示例。


在下文中一共展示了Unifier.clone方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: execute

import jason.asSemantics.Unifier; //导入方法依赖的package包/类
@Override
public Object execute(final TransitionSystem ts, final Unifier un, final Term[] args) throws Exception {
    checkArguments(args);
    if (args.length == 1) {
        return un.unifies(args[0], new NumberTermImpl(random.nextDouble()));
    } else {
        final int max = (int)((NumberTerm)args[1]).solve();

        return new Iterator<Unifier>() {
            int n = 0;
            // we always have a next random number
            public boolean hasNext() { 
                return (n < max || max == 0) && ts.getUserAgArch().isRunning();  
            }
            public Unifier next() {
                Unifier c = un.clone();
                c.unifies(args[0], new NumberTermImpl(random.nextDouble()));
                n++;
                return c;
            }
            public void remove() {}
        };
        
    }
}
 
开发者ID:nickrfer,项目名称:code-sentinel,代码行数:26,代码来源:random.java

示例2: execute

import jason.asSemantics.Unifier; //导入方法依赖的package包/类
@Override public Object execute(final TransitionSystem ts, final Unifier un, final Term[] args) throws Exception {
    checkArguments(args);

    if (!args[0].isVar()) {
        return ts.getAg().getBB().getNameSpaces().contains(args[0]); 
    } else {
        return new Iterator<Unifier>() {
            Iterator<Atom> i  = ts.getAg().getBB().getNameSpaces().iterator();
            Unifier        n  = null;
            
            {
                next(); // consume the first (and set first n value, i.e. the first solution)
            }
            
            public boolean hasNext() {
                return n != null;
            }

            public Unifier next() {
                Unifier c = n;
                
                n = un.clone();
                if (i.hasNext()) { 
                    if (!n.unifiesNoUndo(args[0], i.next()))
                        next();
                } else {
                    n = null;
                }
                
                return c;
            }
            
            public void remove() {}
        };            
    }
}
 
开发者ID:nickrfer,项目名称:code-sentinel,代码行数:37,代码来源:namespace.java

示例3: execute

import jason.asSemantics.Unifier; //导入方法依赖的package包/类
@Override
public Object execute(TransitionSystem ts, final Unifier un, Term[] args) throws Exception {
    checkArguments(args);

    final int start = (int)((NumberTerm)args[1]).solve();
    final int end   = (int)((NumberTerm)args[2]).solve();
    final int step;
    if (args.length == 4)
        step = (int)((NumberTerm)args[3]).solve();
    else
        step = 1;
    if (!args[0].isVar()) {
        // first arg is not a var
        int vl = (int)((NumberTerm)args[0]).solve();
        return vl >= start && vl <= end;
    } else {
        // first arg is a var, backtrack
        final Term var = args[0];

        return new Iterator<Unifier>() {
            int vl = start-step;
            
            public boolean hasNext() {
                if (step > 0)
                    return vl+step <= end;
                else
                    return vl+step >= end;
            }

            public Unifier next() {
                vl += step;
                Unifier c = un.clone();
                c.unifiesNoUndo(var,new NumberTermImpl(vl));
                return c;
            }
            
            public void remove() {}
        };
    }
}
 
开发者ID:nickrfer,项目名称:code-sentinel,代码行数:41,代码来源:range.java

示例4: deleteFromList

import jason.asSemantics.Unifier; //导入方法依赖的package包/类
ListTerm deleteFromList(Term element, ListTerm l, Unifier un) {
    Unifier bak = un;
    ListTerm r = new ListTermImpl();
    ListTerm last = r;
    for (Term t: l) {
        boolean u = un.unifies(element, t); 
        if (u)
            un = bak.clone();
        else
            last = last.append(t.clone());
    }
    return r;
}
 
开发者ID:nickrfer,项目名称:code-sentinel,代码行数:14,代码来源:delete.java

示例5: testUnifClone

import jason.asSemantics.Unifier; //导入方法依赖的package包/类
public void testUnifClone() {
    VarTerm x1 = new VarTerm("X");
    VarTerm x2 = new VarTerm("X");
    assertEquals(x1,x2);
    
    Unifier u1 = new Unifier();
    u1.unifies(x1, new VarTerm("Y"));
    u1.unifies(x2, new VarTerm("Z"));
    Unifier u2 = (Unifier)u1.clone();
    Object o1 = u1.get("X");
    Object o2 = u2.get("X");
    assertEquals(o1,o2);
    
    assertEquals(u1,u2);
}
 
开发者ID:nickrfer,项目名称:code-sentinel,代码行数:16,代码来源:VarTermTest.java

示例6: execute

import jason.asSemantics.Unifier; //导入方法依赖的package包/类
@Override
public Object execute(TransitionSystem ts, final Unifier un, final Term[] args) throws Exception {
    checkArguments(args);
    final Term sublist = args[0];
    
    return new Iterator<Unifier>() {
        Unifier  c = null; // the current response (which is an unifier)
        ListTerm listOutter = ((ListTerm)args[1]);
        List<Term> list = listOutter.getAsList(); // used in the inner loop, Java List is used for faster remove in the end 
        boolean  triedEmpty = false;
        
        public boolean hasNext() {
            if (c == null) // the first call of hasNext should find the first response 
                find();
            return c != null; 
        }

        public Unifier next() {
            if (c == null) find();
            Unifier b = c;
            find(); // find next response
            return b;
        }
        
        void find() {
            while (listOutter != null && !listOutter.isEmpty()) {
                while (!list.isEmpty()) {
                    ListTerm candidate = ASSyntax.createList(list);
                    list.remove(list.size()-1);
                    c = un.clone();
                    if (c.unifiesNoUndo(sublist, candidate)) {
                        return; // found another sublist, c is the current response
                    }
                }
                listOutter = listOutter.getNext();
                if (listOutter == null || listOutter.isVar()) // the case of lists with tail
                    break;
                list = listOutter.getAsList(); 
            }
            if (!triedEmpty) {
                triedEmpty = true;
                c = un.clone();
                if (c.unifiesNoUndo(sublist, ASSyntax.createList())) {
                    return; // found another sublist, c is the current response
                }                   
            }
            c = null; // no more sublists found 
        }

        public void remove() {}
    };
}
 
开发者ID:nickrfer,项目名称:code-sentinel,代码行数:53,代码来源:sublist.java

示例7: execute

import jason.asSemantics.Unifier; //导入方法依赖的package包/类
@Override
public Object execute(TransitionSystem ts, final Unifier un, Term[] args) throws Exception {

    checkArguments(args);

    // execute the internal action

    final Term sublist = args[0];
    final List<Term> list = ((ListTerm)args[1]).getAsList(); // use a Java List for better performance in remove last
    
    return new Iterator<Unifier>() {
        Unifier c = null; // the current response (which is an unifier)
        boolean triedEmpty = false;
        
        public boolean hasNext() {
            if (c == null) // the first call of hasNext should find the first response 
                find();
            return c != null; 
        }

        public Unifier next() {
            if (c == null) find();
            Unifier b = c;
            find(); // find next response
            return b;
        }
        
        void find() {
            while (!list.isEmpty()) {
                ListTerm candidate = ASSyntax.createList(list);
                list.remove(list.size()-1);
                c = un.clone();
                if (c.unifiesNoUndo(sublist, candidate)) {
                    return; // found another sublist, c is the current response
                }
            }
            if (!triedEmpty) {
                triedEmpty = true;
                c = un.clone();
                if (c.unifiesNoUndo(sublist, ASSyntax.createList())) {
                    return; // found another sublist, c is the current response
                }                   
            }
            c = null; // no more sublists found 
        }

        public void remove() {}
    };
}
 
开发者ID:nickrfer,项目名称:code-sentinel,代码行数:50,代码来源:prefix.java

示例8: execute

import jason.asSemantics.Unifier; //导入方法依赖的package包/类
@Override
public Object execute(TransitionSystem ts, final Unifier un, Term[] args) throws Exception {

    checkArguments(args);

    // execute the internal action

    final Term sublist = args[0];
    final Iterator<ListTerm> list = ((ListTerm)args[1]).listTermIterator();
    
    return new Iterator<Unifier>() {
        Unifier c = null; // the current response (which is an unifier)
        public boolean hasNext() {
            if (c == null) // the first call of hasNext should find the first response 
                find();
            return c != null; 
        }

        public Unifier next() {
            if (c == null) 
                find();
            Unifier b = c;
            find(); // find next response
            return b;
        }
        
        void find() {
            while (list.hasNext()) { 
                ListTerm l = list.next();
                if (l.isVar()) // the case of the tail of the list
                    break;
                c = un.clone();
                if (c.unifiesNoUndo(sublist, ASSyntax.createList(l))) {
                    return; // found another sublist, c is the current response
                }
            }
            c = null; // no more sublists found 
        }

        public void remove() {}
    };
}
 
开发者ID:nickrfer,项目名称:code-sentinel,代码行数:43,代码来源:suffix.java

示例9: execute

import jason.asSemantics.Unifier; //导入方法依赖的package包/类
@Override
public Object execute(TransitionSystem ts, final Unifier un, final Term[] args) throws Exception {
    checkArguments(args);

    ListTerm list = (ListTerm)args[1];

    if (args[0].isNumeric()) {
        int index = (int)((NumberTerm)args[0]).solve();

        if (index < 0 || index >= list.size()) {
            throw new JasonException("nth: index "+index+" is out of bounds ("+list.size()+")");
        }

        return un.unifies(args[2], list.get(index));
    }
    
    if (args[0].isVar()) {
        
        final Iterator<Term> ilist = list.iterator();
        
        // return all indexes for thirds arg
        return new Iterator<Unifier>() {
            int index = -1;
            Unifier c = null; // the current response (which is an unifier)
            
            public boolean hasNext() {
                if (c == null) // the first call of hasNext should find the first response 
                    find();
                return c != null; 
            }

            public Unifier next() {
                if (c == null) find();
                Unifier b = c;
                find(); // find next response
                return b;
            }
            
            void find() {
                while (ilist.hasNext()) {
                    index++;
                    Term candidate = ilist.next();
                    c = un.clone();
                    if (c.unifiesNoUndo( args[2], candidate)) {
                        c.unifies(args[0], ASSyntax.createNumber(index));
                        return; // found another response
                    }
                }
                c = null; // no more sublists found 
            }

            public void remove() {}
        };
        
    }
    return false;
}
 
开发者ID:nickrfer,项目名称:code-sentinel,代码行数:58,代码来源:nth.java

示例10: execute

import jason.asSemantics.Unifier; //导入方法依赖的package包/类
@Override
public Object execute(TransitionSystem ts, final Unifier un, Term[] args) throws Exception {
    checkArguments(args);

    final Term member = args[0];
    final Iterator<Term> i = ((ListTerm)args[1]).iterator();

    return new Iterator<Unifier>() {
        Unifier c = null; // the current response (which is an unifier)
        
        public boolean hasNext() {
            if (c == null) // the first call of hasNext should find the first response 
                find();
            return c != null; 
        }

        public Unifier next() {
            if (c == null) find();
            Unifier b = c;
            find(); // find next response
            return b;
        }
        
        void find() {
            while (i.hasNext()) {
                c = un.clone();
                if (c.unifiesNoUndo(member, i.next()))
                    return; // member found in the list, c is the current response
            }
            c = null; // no member is found, 
        }

        public void remove() {}
    };
    
    /* -- old version of the implementation
     * -- problem: even if the user wants only the first member, if search all
    List<Unifier> answers = new ArrayList<Unifier>();
    Unifier newUn = (Unifier)un.clone(); // clone un so as not to change it
    for (Term t: lt) {
        if (newUn.unifies(member, t)) {
            // add this unification to the  answers
            answers.add(newUn);
            newUn = (Unifier)un.clone(); // creates a new clone of un
        }
    }                
    return answers.iterator();
    */
}
 
开发者ID:nickrfer,项目名称:code-sentinel,代码行数:50,代码来源:member.java


注:本文中的jason.asSemantics.Unifier.clone方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。