Example #1
0
vector<int> DParrayConstrained::sample_path() const {
    vector<int> path;

    const int I = size()-1;
    int i = I;

    int state2 = endstate();

    vector<double> transition(nstates());

    while(i >= 0) {
        path.push_back(state2);
        transition.resize(states(i).size());
        for(int s1=0; s1<transition.size(); s1++) {
            int state1 = states(i)[s1];
            transition[s1] = (*this)(i,state1)*GQ(state1,state2);
        }

        int s1 = choose_scratch(transition);
        int state1 = states(i)[s1];

        if (di(state1)) i--;

        state2 = state1;
    }
    assert(i+di(state2)==0);

    std::reverse(path.begin(),path.end());

#ifndef NDEBUG_DP
    check_sampling_probability(path);
#endif

    return path;
}
Example #2
0
efloat_t DParrayConstrained::Pr_sum_all_paths() const
{
    const int I = size()-1;

    double total = 0.0;
    for(int s1=0; s1<states(I).size(); s1++) {
        int state1 = states(I)[s1];
        total += (*this)(I,state1) * GQ(state1,endstate());
    }

    return pow<efloat_t>(2.0,scale(I)) * total;
}
Example #3
0
// We can ignore scale(i) here, because it factors out.
efloat_t DParrayConstrained::path_P(const vector<int>& g_path) const
{
    const int I = size()-1;
    int i=I;
    int l=g_path.size()-1;
    int state2 = g_path[l];

    vector<double> transition(nstates());

    efloat_t Pr=1.0;
    while (l>0)
    {
        transition.resize(states(i).size());
        for(int s1=0; s1<transition.size(); s1++) {
            int state1 = states(i)[s1];
            transition[s1] = (*this)(i,state1)*GQ(state1,state2);
        }

        int state1 = g_path[l-1];
        int s1 = find_index(states(i),state1);
        assert(s1 != -1);
        double p = choose_P(s1,transition);
        assert(p > 0.0);

        if (di(state1)) i--;

        l--;
        state2 = state1;
        Pr *= p;
        assert(Pr > 0.0);
    }

    // In column 0, all states are allowed:
    // - silent states can't contradict anything
    // - non-silent states reprent the start state.
    transition.resize(states(0).size());

    // include probability of choosing 'Start' vs ---+ !
    for(int state1=0; state1<nstates(); state1++)
        transition[state1] = (*this)(0,state1) * GQ(state1,state2);

    // Get the probability that the previous state was 'Start'
    double p=0.0;
    for(int state1=0; state1<nstates(); state1++)
        if (not silent(state1))
            p += choose_P(state1,transition);

    Pr *= p;

    assert(Pr > 0.0);
    return Pr;
}
Example #4
0
void initVideo(void)
{
	/* We need access to DS hardware */
	FeOS_DirectMode();
	vramSetPrimaryBanks (VRAM_A_LCD, VRAM_B_LCD, VRAM_C_SUB_BG_0x06200000, VRAM_D_LCD);
	/* Init video engine for the SUB_SCREEN */
	videoSetModeSub(MODE_5_2D);
	vramSetBankI(VRAM_I_SUB_SPRITE);
	oamEnable(states(SUB_SCREEN));
	oamInit(states(SUB_SCREEN), SpriteMapping_1D_128, false);
	/* Init video engine for the MAIN_SCREEN */
	init3D();
}
Example #5
0
void CursorDropdown::onStateDeactivate(StateEvent* event)
{
    if (!_deactivated)
    {
        auto game = Game::getInstance();
        auto mouse = game->mouse();
        // workaround to get rid of cursor disappearing issues
        std::vector<unsigned int> icons;
        while (mouse->states()->size() > _initialMouseStack)
        {
            icons.push_back(mouse->state());
            mouse->popState();
        }
        if (icons.size() > 0)
        {
            icons.pop_back(); // remove empty icon from CursorDropdown state
            // place only new icons back in stack
            for (auto it = icons.rbegin(); it != icons.rend(); it++)
            {
                mouse->pushState(*it);
            }
        }
        mouse->setX(_initialX);
        mouse->setY(_initialY);
        _deactivated = true;
    }
}
Example #6
0
void Game::Gameplay_Draw()
{
	for (unsigned int i = 0; i < m_gameObjects.size(); i++)
	{
		m_gameObjects[i]->Render(m_renderer, m_currentCam);

		if (m_gameObjects[i]->GetObjectType() == "SphereEnemy")
		{
			if (static_cast <SphereEnemy*> (m_gameObjects[i])->Bullets[0]->getState() == 0)
			static_cast <SphereEnemy*> (m_gameObjects[i])->Bullets[0]->Render(m_renderer,m_currentCam);
		}
	}

	for (unsigned int i = 0; i < m_player->Bullets.size(); i++)
	{
		if (m_player->Bullets[i]->getState() == 0)
		m_player->Bullets[i]->Render(m_renderer,m_currentCam);
	}

	//When we want to draw 2D objects we need to do it within the Begin and End calls of the Sprite Batch
	CommonStates states(m_renderer->GetDevice());
	m_spriteBatch->Begin(SpriteSortMode_Deferred, states.NonPremultiplied());

	m_arial->DrawString(m_spriteBatch, L"Lives:", Vector2(150, 100));
	std::wstring health_string = std::to_wstring(m_player->getHealth());
	m_arial->DrawString(m_spriteBatch, &health_string[0], Vector2(200, 100));


	m_arial->DrawString(m_spriteBatch, L"Score:", Vector2(150, 150));
	std::wstring score_string = std::to_wstring(m_player->getScore());
	m_arial->DrawString(m_spriteBatch, &score_string[0], Vector2(200, 150));

	if (m_player->reloading)
	{
		m_arial->DrawString(m_spriteBatch, L"Reload Timer:", Vector2(750, 100));
		std::wstring reloadTime_string = std::to_wstring(m_player->reloadCounter);
		m_arial->DrawString(m_spriteBatch, &reloadTime_string[0], Vector2(850, 100));
	}
	m_arial->DrawString(m_spriteBatch, L"Current Weapon:", Vector2(450, 100));

	std::wstring currentWeapon = m_player->enumToString(m_player->currentWeapon);
	const wchar_t* widecstr = currentWeapon.c_str();

	m_arial->DrawString(m_spriteBatch,widecstr, Vector2(580, 100));

	m_arial->DrawString(m_spriteBatch, L"Ammo:", Vector2(450, 150));
	std::wstring ammo_string = std::to_wstring(m_player->Bullets.size() - m_player->shotsCounter);
	m_arial->DrawString(m_spriteBatch, &ammo_string[0], Vector2(505, 150));
	m_arial->DrawString(m_spriteBatch, L"/", Vector2(523, 150));
	std::wstring maxAmmo_string = std::to_wstring(m_player->Bullets.size());
	m_arial->DrawString(m_spriteBatch, &maxAmmo_string[0], Vector2(530, 150));





	//m_button->Render();		//The Button rendering needs to be done within the Begin and End calls of the SpriteBatch

	m_spriteBatch->End();
}
TEST(WebKit2, ResizeWindowAfterCrash)
{
    WKRetainPtr<WKContextRef> context(AdoptWK, WKContextCreate());
    TestStatesData states(context.get());

    WKPageLoaderClientV0 loaderClient;
    memset(&loaderClient, 0, sizeof(loaderClient));

    loaderClient.base.version = 0;
    loaderClient.base.clientInfo = &states;
    loaderClient.didFinishLoadForFrame = didFinishLoad;
    loaderClient.processDidCrash = didCrash;

    WKPageSetPageLoaderClient(states.webView.page(), &loaderClient.base);

    WKRetainPtr<WKURLRef> url = adoptWK(WKURLCreateWithUTF8CString("about:blank"));
    // Load a blank page and next kills WebProcess.
    WKPageLoadURL(states.webView.page(), url.get());
    Util::run(&states.firstLoad);
    WKPageTerminate(states.webView.page());

    // Let's try load a page and see what happens.
    WKPageLoadURL(states.webView.page(), url.get());
    Util::run(&states.resizeAfterCrash);
}
int main() {


  typedef ColinearityKinematicConstraintT<colinearityKinematic::PhiTheta> ColinearityConstraint;
  { ColinearityConstraint cc; std::cout << " cc " << cc.numberOfEquations() << std::endl;}

 
  typedef CombinedKinematicConstraintT<std::tuple<ColinearityConstraint,VertexKinematicConstraintT>, 2> CKC;
  CKC ckc(std::make_tuple(ColinearityConstraint(),VertexKinematicConstraintT()));

  std::cout << CKC::nTrk << " " << CKC::nDim 
            << " " << ckc.numberOfEquations() 
            << std::endl;

  std::vector<KinematicState> states(2);
  const GlobalPoint point;
  const GlobalVector mf;
  ckc.init(states,point,mf);

  CKC::valueType v = ckc.value();
  CKC::parametersDerivativeType pad =  ckc.parametersDerivative();
  CKC::positionDerivativeType pod = ckc.positionDerivative();

  std::cout << v(0) << " " << pad(0,0) << " " << pod(0,0) << std::endl;

  KinematicConstrainedVertexFitterT<CKC::nTrk,CKC::nDim> kinefit(0);


  return 0;
}
 void countoccur(){
     for(int i = 0; i < sz; ++i){ occur[i] = 1 - isclone[i]; }
     vii states(sz);
     for(int i = 0; i < sz; ++i){ states[i] = ii(len[i],i); }
     sort(states.begin(), states.end());
     for(int i = size(states)-1; i >= 0; --i){ int v = states[i].second;
         if(link[v] != -1) { occur[link[v]] += occur[v]; } } }
Example #10
0
std::vector<typename state_type<Domain>::type> random(const Domain& dom, unsigned int n) {
	std::vector<typename state_type<Domain>::type> states(n);
	for(std::size_t i=0; i<states.size(); i++) {
		states[i] = random(dom);
	}
	return states;
}
Example #11
0
void CritterDialog::_selectAnswer(size_t i)
{
    if (i >= _answers.size()) throw Exception("No answer with number " + std::to_string(i));

    auto game = Game::getInstance();
    auto dialog = dynamic_cast<CritterInteract*>(game->states()->at(game->states()->size() - 2));

    // @todo optimize
    int newOffset = dialog->script()->script()->procedures()->at(_functions.at(i))->bodyOffset();
    int oldOffset = dialog->script()->programCounter() - 2;
    deleteAnswers();
    dialog->script()->dataStack()->push(0); // arguments counter;
    dialog->script()->returnStack()->push(oldOffset); // return adrress
    dialog->script()->setProgramCounter(newOffset);
    dialog->script()->run();
}
Example #12
0
    void undo() const override
    {
        auto& scenar = m_scenarioPath.find();
        auto& globalEvent = scenar.event(m_destinationEventId);

        Deserializer<DataStream> s{m_serializedEvent};
        auto recreatedEvent = new EventModel{s, &scenar};

        auto states_in_event = recreatedEvent->states();
        // we remove and re-add states in recreated event
        // to ensure correct parentship between elements.
        for(auto stateId : states_in_event)
        {
            recreatedEvent->removeState(stateId);
            globalEvent.removeState(stateId);
        }
        for(auto stateId : states_in_event)
        {
            recreatedEvent->addState(stateId);
            scenar.states.at(stateId).setEventId(m_movingEventId);
        }

        scenar.events.add(recreatedEvent);

        if(recreatedEvent->timeNode() != globalEvent.timeNode())
        {
            auto& tn = scenar.timeNode(globalEvent.timeNode());
            tn.addEvent(m_movingEventId);
            m_mergeTimeNodesCommand->undo();
        }

        updateEventExtent(m_destinationEventId, scenar);

    }
Example #13
0
static void nrn_state(_NrnThread* _nt, _Memb_list* _ml, int _type) {
 double _break, _save;
double* _p; Datum* _ppvar; Datum* _thread;
Node *_nd; double _v; int* _ni; int _iml, _cntml;
#if CACHEVEC
    _ni = _ml->_nodeindices;
#endif
_cntml = _ml->_nodecount;
_thread = _ml->_thread;
for (_iml = 0; _iml < _cntml; ++_iml) {
 _p = _ml->_data[_iml]; _ppvar = _ml->_pdata[_iml];
 _nd = _ml->_nodelist[_iml];
#if CACHEVEC
  if (use_cachevec) {
    _v = VEC_V(_ni[_iml]);
  }else
#endif
  {
    _nd = _ml->_nodelist[_iml];
    _v = NODEV(_nd);
  }
 _break = t + .5*dt; _save = t;
 v=_v;
{
  ek = _ion_ek;
 { {
 for (; t < _break; t += dt) {
   states(_p, _ppvar, _thread, _nt);
  
}}
 t = _save;
 } }}

}
Example #14
0
int
fm<Label>::is_deterministic() const
{
	int		j;
	set<state>	all_states;
	set<Label>	alphabet;
	fm<Label>	t;

	// if more than one start state, it's not deterministic
	if (start_states.size() != 1)
		return 0;

	// collect alphabet and states
	labels(alphabet);
	states(all_states);

	// for every state, check for all instructions
	for (int i=0; i<all_states.size(); ++i)
		for (j=0; j<alphabet.size(); ++j)
		{
			select(alphabet[j], all_states[i], SOURCE, t);
			if (t.size() > 1)
				return 0;
		}
	return 1;
}
Example #15
0
static void nrn_state(_NrnThread* _nt, _Memb_list* _ml, int _type){
 double _break, _save;
Node *_nd; double _v; int* _ni; int _iml, _cntml;
#if CACHEVEC
    _ni = _ml->_nodeindices;
#endif
_cntml = _ml->_nodecount;
for (_iml = 0; _iml < _cntml; ++_iml) {
 _p = _ml->_data[_iml]; _ppvar = _ml->_pdata[_iml];
 _nd = _ml->_nodelist[_iml];
#if CACHEVEC
  if (use_cachevec) {
    _v = VEC_V(_ni[_iml]);
  }else
#endif
  {
    _nd = _ml->_nodelist[_iml];
    _v = NODEV(_nd);
  }
 _break = t + .5*dt; _save = t;
 v=_v;
{
  ek = _ion_ek;
 { {
 for (; t < _break; t += dt) {
 error =  states();
 if(error){fprintf(stderr,"at line 64 in file KA_i1.mod:\n  SOLVE states METHOD cnexp\n"); nrn_complain(_p); abort_run(error);}
 
}}
 t = _save;
 } }}

}
Example #16
0
 //!Generate a hit table from a multiple traceback paths
 //! Hit table is 2D table describing how many times a state was called at a particular position in the sequence
 heatTable* multiTraceback::get_hit_table(){
     if (table!=NULL){
         delete table;
     }
     
     //Over the lenght of the sequence
     model* hmm = ((*pathAccess[0]).first).getModel();
     size_t sequenceSize=((*pathAccess[0]).first).size();
     size_t stateSize=hmm->state_size();
     
     
     std::vector<int> states(stateSize,0);
     table = new heatTable(sequenceSize,states);
     
     std::map<traceback_path,int>::iterator it;
     
     for( it =paths.begin(); it!=paths.end();it++){
         int count = (*it).second;
         for(size_t position=0;position<sequenceSize;position++){
             int tbState=(*it).first[position];
             (*table)[position][tbState]+=count;
         }
     }
     return table;
 }
Example #17
0
 virtual WhichFstComposeSpecials whichInputFstComposeSpecials() const {
   WhichFstComposeSpecials r;
   for (StateIdInterval states(possiblyInputTerminalLabeledStates()); states.first < states.second;
        ++states.first)
     r.check(inputLabel(states.first));
   return r;
 }
Example #18
0
std::vector<int>
galleryd::queue::status(item_t &items, const std::string &category)
{
    std::vector<int> states (items.size());

    // build sql statement
    auto stmt = category.empty()
        ? query_status_(items)
        : query_status_with_category_(items, category);

    // insert all found items into a map
    std::map<std::string, int> lookup;
    for(auto&& row : stmt)
        lookup.emplace(row.as_string(0), row.as_int(1));

    // build array with state-values for each item in the request.
    // if the item doesn't exist, the value is '0'.
    std::map<std::string, int>::const_iterator iter, end = lookup.end();
    for(size_t i = 0, e = items.size(); i < e; ++i)
    {
        iter      = lookup.find(items[i]);
        states[i] = iter == end ? 0 : iter->second;
    }

    return states;
}
Example #19
0
void ompl::base::SpaceInformation::samplesPerSecond(double &uniform, double &near, double &gaussian,
                                                    unsigned int attempts) const
{
    StateSamplerPtr ss = allocStateSampler();
    std::vector<State *> states(attempts + 1);
    allocStates(states);

    time::point start = time::now();
    for (unsigned int i = 0; i < attempts; ++i)
        ss->sampleUniform(states[i]);
    uniform = (double)attempts / time::seconds(time::now() - start);

    double d = getMaximumExtent() / 10.0;
    ss->sampleUniform(states[attempts]);

    start = time::now();
    for (unsigned int i = 1; i <= attempts; ++i)
        ss->sampleUniformNear(states[i - 1], states[i], d);
    near = (double)attempts / time::seconds(time::now() - start);

    start = time::now();
    for (unsigned int i = 1; i <= attempts; ++i)
        ss->sampleGaussian(states[i - 1], states[i], d);
    gaussian = (double)attempts / time::seconds(time::now() - start);

    freeStates(states);
}
Example #20
0
void
sge::opengl::vf::part::use_me(
	sge::opengl::vf::pointer const _src
) const
{
	sge::opengl::vf::client_state_combiner states(
		log_,
		context_
	);

	for(
		auto const &actor
		:
		actors_
	)
		(*actor)(
			states,
			fcppt::cast::from_void_ptr<
				unsigned char const *
			>(
				_src
			)
			+
			actor->offset().get()
		);
}
std::vector<state> sa_init(size_t &size, size_t &last) {
    std::vector<state> states(1);
    size = last = 0;
    states[0].len = 0;
    states[0].link = -1;
    ++size;
    return states;
}
Example #22
0
TEST(stateset, orthonormalization_highmem) {
	RNG rng(RNG::produce_random_seed());
	const DataLayout dl(16, 16, 1.0);
	StateSet states(8, dl, HighMem);
	states.init_to_gaussian_noise(rng);
	states.orthonormalize();
	EXPECT_LT(states.how_orthonormal(), 16*machine_epsilon);
}
Example #23
0
static void add_rules(StateMachinePtr sm, BindingsPtr bindings, NodePtr root) {
   if (root->get_op() == Op::sm_rules) {
      add_rules(sm, bindings, root->get_operand(0));
      root = root->get_operand(1);
   }
   assert(root->get_op() == Op::sm_rule);
   if (root->size() == 1) {
      // handler
      root = root->get_operand(0);
      assert(root->get_op() == Op::ON);
      assert(root->get_operand(0)->get_op() == Op::CLOSE);
      root = root->get_operand(1);
      assert(root->get_op() == Op::sm_handler);
      if (root->size() == 1) {
	 StateSet states;
	 sm->add_close_handler(states, root->get_operand(0));
      } else {
	 StateSet states(sm->get_nofstates());
	 get_states(sm, root->get_operand(0), states);
	 sm->add_close_handler(states, root->get_operand(1));
      }
   } else {
      // regular rule
      NodePtr smcond = root->get_operand(0);
      StateMachineRulePtr rule;
      NodePtr node_expr;
      if (smcond->size() == 2) {
	 NodePtr tree_expr = smcond->get_operand(0);
	 NodeTypeSet nodetypes(nof_node_types(bindings));
	 get_node_expression(bindings, smcond->get_operand(1),
	    nodetypes, node_expr);
	 rule = std::make_shared<StateMachineRule>(sm,
		  tree_expr, nodetypes, bindings->get_rules());
      } else {
	 if (smcond->get_operand(0)->get_op() == Op::cfg_node_expression) {
	    NodeTypeSet nodetypes(nof_node_types(bindings));
	    get_node_expression(bindings, smcond->get_operand(0),
	       nodetypes, node_expr);
	    rule = std::make_shared<StateMachineRule>(sm,
	       nodetypes, bindings->get_rules());
	 } else {
	    NodePtr tree_expr = smcond->get_operand(0);
	    rule = std::make_shared<StateMachineRule>(sm,
	       tree_expr, bindings->get_rules());
	 }
      }
      if (node_expr) {
	 rule->add_node_condition(node_expr);
      }
      if (root->get_operand(1)->get_op() == Op::sm_block) {
	 NodePtr smblock = root->get_operand(1);
	 rule->add_alternative(create_alternative(sm, smblock));
      } else {
	 add_alternatives(sm, rule, bindings, root->get_operand(1));
      }
      sm->add_rule(rule);
   }
}
Example #24
0
    Perturb10(const vle::devs::DynamicsInit& init, const vle::devs::InitEventList& events) :
        vf::Statechart(init, events)
    {
        states(this) << A << B;
        transition(this, A, B) << after(5.) << send(&Perturb10::out1);
        transition(this, B, A) << after(5.) << send(&Perturb10::out2);

        initialState(A);
    }
Example #25
0
 Perturb7(const vle::devs::DynamicsInit& init, const vle::devs::InitEventList& events) :
     vf::Statechart(init, events), a(0)
 {
     states(this) << A;
     transition(this, A, A) << after(5.)
                                << send(&Perturb7::out);
     state(this, A) << eventInState("a", &Perturb7::a_in);
     initialState(A);
 }
Example #26
0
void Level::Impl::checkWinMission()
{
  auto city = game->city();
  auto& conditions = city->victoryConditions();

  int culture = city->culture();
  int prosperity = city->prosperity();
  int favour = city->states().favor;
  int peace = city->peace();
  int population = city->states().population;
  bool success = conditions.isSuccess(culture, prosperity, favour, peace, population);

  if (success)
  {
    events::dispatch<ScriptFunc>("OnMissionWin");
    steamapi::missionWin(conditions.name());
  }
}
Example #27
0
// We don't care about things below.
// They will look the same all time
void Engine::loop()
{
    while( core->isOpen() )
    {
        events();
        states();
        // After timer ...
    }
}
Example #28
0
void RenderTheme::adjustRepaintRect(const RenderObject& o, IntRect& r)
{
#if USE(NEW_THEME)
    ControlStates states(extractControlStatesForRenderer(o));
    m_theme->inflateControlPaintRect(o.style().appearance(), &states, r, o.style().effectiveZoom());
#else
    UNUSED_PARAM(o);
    UNUSED_PARAM(r);
#endif
}
Example #29
0
void RenderTheme::adjustRepaintRect(const RenderObject& renderer, FloatRect& rect)
{
#if USE(NEW_THEME)
    ControlStates states(extractControlStatesForRenderer(renderer));
    m_theme->inflateControlPaintRect(renderer.style().appearance(), states, rect, renderer.style().effectiveZoom());
#else
    UNUSED_PARAM(renderer);
    UNUSED_PARAM(rect);
#endif
}
Example #30
0
    Perturb7(const vd::DynamicsInit& init, const vd::InitEventList& events) :
        vf::Statechart(init, events)
    {
        states(this) << A;

        transition(this, A, A) << after(5.)
                               << send(&Perturb7::out);

        initialState(A);
    }