tactic clear_tactic(name const & n) { auto fn = [=](environment const &, io_state const &, proof_state const & _s) -> optional<proof_state> { if (!_s.get_goals()) { throw_no_goal_if_enabled(_s); return none_proof_state(); } proof_state s = apply_substitution(_s); goals const & gs = s.get_goals(); goal g = head(gs); goals tail_gs = tail(gs); if (auto p = g.find_hyp(n)) { expr const & h = p->first; unsigned i = p->second; buffer<expr> hyps; g.get_hyps(hyps); hyps.erase(hyps.size() - i - 1); if (depends_on(g.get_type(), h)) { throw_tactic_exception_if_enabled(s, sstream() << "invalid 'clear' tactic, conclusion depends on '" << n << "'"); return none_proof_state(); } if (auto h2 = depends_on(i, hyps.end() - i, h)) { throw_tactic_exception_if_enabled(s, sstream() << "invalid 'clear' tactic, hypothesis '" << *h2 << "' depends on '" << n << "'"); return none_proof_state(); } name_generator ngen = s.get_ngen(); expr new_type = g.get_type(); expr new_meta = mk_app(mk_metavar(ngen.next(), Pi(hyps, new_type)), hyps); goal new_g(new_meta, new_type); substitution new_subst = s.get_subst(); assign(new_subst, g, new_meta); proof_state new_s(s, goals(new_g, tail_gs), new_subst, ngen); return some_proof_state(new_s); } else { throw_tactic_exception_if_enabled(s, sstream() << "invalid 'clear' tactic, goal does not have a hypothesis " << " named '" << n << "'"); return none_proof_state(); } }; return tactic01(fn); }
PyObject* IKSolver::solve(int iters,double tol) { RobotIKFunction f(*robot.robot); vector<IKGoal> goals(objectives.size()); for(size_t i=0;i<objectives.size();i++) goals[i] = objectives[i].goal; f.UseIK(goals); if(activeDofs.empty()) GetDefaultIKDofs(*robot.robot,goals,f.activeDofs); else f.activeDofs.mapping = activeDofs; RobotIKSolver solver(f); if(useJointLimits) { if(qmin.empty()) solver.UseJointLimits(); else solver.UseJointLimits(Vector(qmin),Vector(qmax)); } solver.solver.verbose = 0; bool res = solver.Solve(tol,iters); robot.robot->UpdateGeometry(); PyObject* tuple = PyTuple_New(2); PyTuple_SetItem(tuple,0,PyBool_FromLong(res)); PyTuple_SetItem(tuple,1,PyInt_FromLong(iters)); return tuple; }
tactic revert_tactic(name const & n) { auto fn = [=](environment const &, io_state const &, proof_state const & s) -> optional<proof_state> { goals const & gs = s.get_goals(); if (empty(gs)) { throw_no_goal_if_enabled(s); return none_proof_state(); } goal g = head(gs); goals tail_gs = tail(gs); if (auto p = g.find_hyp(n)) { expr const & h = p->first; unsigned i = p->second; buffer<expr> hyps; g.get_hyps(hyps); hyps.erase(hyps.size() - i - 1); if (optional<expr> other_h = depends_on(i, hyps.end() - i, h)) { throw_tactic_exception_if_enabled(s, sstream() << "invalid 'revert' tactic, hypothesis '" << local_pp_name(*other_h) << "' depends on '" << local_pp_name(h) << "'"); return none_proof_state(); // other hypotheses depend on h } name_generator ngen = s.get_ngen(); expr new_type = Pi(h, g.get_type()); expr new_meta = mk_app(mk_metavar(ngen.next(), Pi(hyps, new_type)), hyps); goal new_g(new_meta, new_type); substitution new_subst = s.get_subst(); assign(new_subst, g, mk_app(new_meta, h)); proof_state new_s(s, goals(new_g, tail_gs), new_subst, ngen); return some_proof_state(new_s); } else { throw_tactic_exception_if_enabled(s, sstream() << "invalid 'revert' tactic, unknown hypothesis '" << n << "'"); return none_proof_state(); } }; return tactic01(fn); }
Team::Team(QObject *parent, const char *name) : QObject(parent,name) { wins(0); losses(0); ties(0); goals(0); generations(0); Bots.clear(); }
/***************************************************************************************** * Implementation of State * NOTE: 20140612. From what I can tell from looking at the HSFC code a state isn't * in some sense valid until it has had the legal moves calculated from it. Or at least * you cannot run Play() from a state that has not had legal moves calculated. So as * a hack I will calculate (and throw away) the legal moves whenever I create a state and * whenever I run Play(). *****************************************************************************************/ void State::initialize(){ // Hack to calculate legal moves so that the state will now be in a good "state". if (!isTerminal()) { std::vector<PlayerMove> legalMoves; legals(std::back_inserter(legalMoves)); } else { goals(); } }
void IKSolver::getActiveDofs(std::vector<int>& out) { if(activeDofs.empty()) { vector<IKGoal> goals(objectives.size()); for(size_t i=0;i<objectives.size();i++) goals[i] = objectives[i].goal; ArrayMapping map; GetDefaultIKDofs(*robot.robot,goals,map); out = map.mapping; } else { out = activeDofs; } }
tactic intros_tactic(list<name> _ns, bool relax_main_opaque) { auto fn = [=](environment const & env, io_state const &, proof_state const & s) { list<name> ns = _ns; goals const & gs = s.get_goals(); if (empty(gs)) { throw_no_goal_if_enabled(s); return optional<proof_state>(); } goal const & g = head(gs); name_generator ngen = s.get_ngen(); auto tc = mk_type_checker(env, ngen.mk_child(), relax_main_opaque); expr t = g.get_type(); expr m = g.get_meta(); bool gen_names = empty(ns); try { while (true) { if (!gen_names && is_nil(ns)) break; if (!is_pi(t)) { if (!is_nil(ns)) { t = tc->ensure_pi(t).first; } else { expr new_t = tc->whnf(t).first; if (!is_pi(new_t)) break; t = new_t; } } name new_name; if (!is_nil(ns)) { new_name = head(ns); ns = tail(ns); } else { new_name = get_unused_name(binding_name(t), m); } expr new_local = mk_local(ngen.next(), new_name, binding_domain(t), binding_info(t)); t = instantiate(binding_body(t), new_local); m = mk_app(m, new_local); } goal new_g(m, t); return some(proof_state(s, goals(new_g, tail(gs)), ngen)); } catch (exception &) { return optional<proof_state>(); } }; return tactic01(fn); }
void Team::randomTeam(unsigned int size) { unsigned int numrules; unsigned int mass; wins(0); losses(0); ties(0); goals(0); name("Team Stochastic"); for (unsigned int i=0; i<size; i++) { numrules = Random::randint(100,200); // pick a random number of rules for each bot mass = Random::randint(1,10); // pick a random number for the bot mass Bot *NewBot = new Bot(this); NewBot->randomBot(numrules, mass); insertBot(NewBot); } }
void IKSolver::getJacobian(std::vector<std::vector<double> >& out) { RobotIKFunction f(*robot.robot); vector<IKGoal> goals(objectives.size()); for(size_t i=0;i<objectives.size();i++) goals[i] = objectives[i].goal; f.UseIK(goals); if(activeDofs.empty()) GetDefaultIKDofs(*robot.robot,goals,f.activeDofs); else f.activeDofs.mapping = activeDofs; Vector x(f.activeDofs.Size()); Matrix J; f.GetState(x); J.resize(f.NumDimensions(),x.n); f.Jacobian(x,J); //copy to out copy(J,out); }
void goalscode_produce(T_PTR_tree entry, ISTSharingTree *unsafe) { goals(entry, unsafe); }