Example #1
0
void SaccadeMotorProgram::delta_ext(double e, const Bag<IO_Type>& xb)
{
	_time += e;
	if (!_saccades.empty())
	{
		//Rcout << _time << " There are " << _saccades.size() << " saccades in the motor queue." << endl;
		list<Saccade*>::const_iterator si = _saccades.begin();
		for(; si != _saccades.end(); si++)
		{
			(*si)->nonlabile_t -= e;
		}
	}
	Bag<IO_Type>::const_iterator iter = xb.begin();
	for (; iter != xb.end(); iter++)
	{
		Saccade* s = new Saccade(*((*xb.begin()).value));
		s->labile_stop = _time;
		s->nonlabile_start = _time;
		s->nonlabile_t = ::Rf_rgamma(((_mean*_mean)/(_stdev*_stdev)),(_stdev*_stdev)/_mean);
		_saccades.push_back(s);
	}
	_saccades.sort(sortNonLabile);
	//printf("%f\t    SaccadeMotorProgram: Starting non-labile programming for saccade[id=%d]\n", _time, _saccade->id);
	//printf("%f\t    SaccadeMotorProgram: Next event at %f\n", _time, _time+_threshold);
}
Example #2
0
int main(int argc, char** argv)
{
	// Get the parameters for the experiment from the command line
	if (argc != 4) {
		cout << "freq left_throttle right_throttle" << endl;
		return 0;
	}
	// Get the frequency of the voltage signal from the first argument
	double freq = atof(argv[1]);
	// Create a command from the driver that contains the duty ratios and
	// directions.
	SimPacket sim_command;
	sim_command.left_power = atof(argv[2]);
	sim_command.right_power = atof(argv[3]);
	// Create computer, simulator, and event listener. 
	Computer* computer = new Computer(freq);
	Simulator<SimEvent>* sim = new Simulator<SimEvent>(computer);
	ComputerListener* l = new ComputerListener(computer);
	// Add an event listener to plot the voltage signals
	sim->addEventListener(l);
	// Inject the driver command into the simulation at time 0
	Bag<Event<SimEvent> > input;
	SimEvent cmd(sim_command);
	Event<SimEvent> event(computer,cmd);
	input.insert(event);
	sim->computeNextState(input,0.0);
	// Run the simulation 
	while (sim->nextEventTime() <= 0.004)
		sim->execNextEvent();
	// Clean up and exit
	delete sim; delete computer; delete l;
	return 0;
}
Example #3
0
void LoadControl::delta_ext(double e, const Bag<PortValue<BasicEvent*> >& xb)
{
	Bag<PortValue<BasicEvent*> >::const_iterator iter = xb.begin();
	for (; iter != xb.end(); iter++)
	{
		GenrSampleEvent* measurement = dynamic_cast<GenrSampleEvent*>((*iter).value);
		if (measurement->freqBreakerOpen()) fdata.erase(measurement->getBusID());
		else fdata[measurement->getBusID()] = measurement->getRotorSpeed();
	}
	// Compute adjustment fraction
	double modified_adjustment = 0.0;
	// Get average frequency
	map<unsigned,double>::iterator fiter = fdata.begin();
	for (; fiter != fdata.end(); fiter++)
	{
		modified_adjustment += (*fiter).second;
	}
	modified_adjustment /= fdata.size();
	// Normalize to a percentage and apply the gain
	modified_adjustment *= (K/FreqTol);
	// Signal?
	if (!(fabs(modified_adjustment) <= max_adjust))
	{
		if (modified_adjustment > 0.0) modified_adjustment = max_adjust;
		else modified_adjustment = -max_adjust;
	}
	signal = adjustment != modified_adjustment;
	adjustment = modified_adjustment;
	assert(fabs(adjustment) <= max_adjust);
}
Example #4
0
static MonomialIdeal *FrobbyAlexanderDual(const MonomialIdeal *I,
                                          const mpz_t *topvec)
{
  int nv = I->topvar() + 1;
  int *exp = newarray_atomic(int, nv);
  Frobby::Ideal F(nv);
  for (Index<MonomialIdeal> i = I->first(); i.valid(); i++)
    {
      Bag *b = I->operator[](i);
      varpower::to_ntuple(nv, b->monom().raw(), exp);

      if (M2_gbTrace >= 4) fprintf(stderr, "adding ");
      for (int j = 0; j < nv; j++)
        {
          if (M2_gbTrace >= 4) fprintf(stderr, "%d ", exp[j]);
          F.addExponent(exp[j]);
        }
      if (M2_gbTrace >= 4) fprintf(stderr, "\n");
    }

  // Now create the consumer object, and call Frobby
  MyIdealConsumer M(I->get_ring(), nv);
  Frobby::alexanderDual(F, topvec, M);
  deletearray(exp);
  // Extract the answer as a MonomialIdeal
  return M.result();
}
Example #5
0
int main()
{
	CircuitExt* test_model = new CircuitExt();
	Hybrid<OMC_ADEVS_IO_TYPE>* hybrid_model =
		new Hybrid<OMC_ADEVS_IO_TYPE>(
		test_model,
		new rk_45<OMC_ADEVS_IO_TYPE>(test_model,1E-7,0.001),
		new linear_event_locator<OMC_ADEVS_IO_TYPE>(test_model,1E-7));
        // Create the simulator
        Simulator<OMC_ADEVS_IO_TYPE>* sim =
			new Simulator<OMC_ADEVS_IO_TYPE>(hybrid_model);
		// Check initial values
		test_model->print_state();
		// Run the simulation, testing the solution as we go
        while (sim->nextEventTime() <= 1.0)
		{
			sim->execNextEvent();
			test_model->print_state();
			test_model->test_state();
		}
		Bag<Event<double> > xb;
		Event<double> event(hybrid_model,0.0);
		xb.insert(event);
		sim->computeNextState(xb,1.0);
		while (sim->nextEventTime() <= 5.0)
		{
			sim->execNextEvent();
			test_model->print_state();
			test_model->test_state();
		}
        delete sim;
		delete hybrid_model;
        return 0;
}
Example #6
0
Digraph& Digraph::operator=(const Digraph& G) {
	printf("Assigning Digraph\n");
	if (this == &G) return *this;

	// Free memory
	delete[] adj_;

	// Allocate memory
	V_ = G.V_;
	E_ = G.E_;
	Bag<int>* new_adj = new Bag<int>[G.V_];

	// Copy elements
	for (int v = 0; v < G.V_; v++) {
		// reverse so that adjacency list is in the same order as original
		Bag<int> reverse;
		for (int w : G.adj_[v])
			reverse.add(w);
		for (int w : reverse)
			new_adj[v].add(w);
	}

	// Reassign variables
	adj_ = new_adj;

	return *this;
}
Example #7
0
/**
 * This is to test the use of template iterators inside of
 * a template class. The main purpose of the test is to
 * make sure the template instantiation works as intended.
 */
void test1()
{
	Bag<int> b;
	b.insert(0);
	template_test<int> t;
	int* array = t.to_array(b);
	assert(array[0]==0);
}
Example #8
0
void engine<VertexType, EdgeType>::run(){
  int iterationCount = 0;
  Bag<Scheduler::update_task>* b = scheduler->get_task_bag();
  while (b->numElements() > 0 /*&& iterationCount < 40*/) {
    iterationCount++;
    parallel_process(b); 
    b = scheduler->get_task_bag(); 
  }
}
Example #9
0
	Component * EntityManager::getComponent(Entity & e, ComponentType & type) {
		Bag<Component*>* bag = componentsByType.get(type.getId());
    
		if (bag != NULL && e.getId() < bag->getCapacity()) {
			return bag->get(e.getId());
		}
    
		return NULL;
	}
Example #10
0
typename Bag::value_type min(const Bag & b)
{
    typename Bag::const_iterator it;
    typename Bag::value_type m = *b.begin();
    for (it = b.begin(); it != b.end(); ++it)
        if (*it < m)
            m = *it;
    return m;
}
Example #11
0
void Generator::gc_output(Bag<IO_Type>& g)
{
	// Delete the customer that was produced as output
	Bag<IO_Type>::iterator i;
	for (i = g.begin(); i != g.end(); i++)
	{
		delete (*i).value;
	}
}
Example #12
0
void DirectedDFS::dfs(DirGraph& G, int v){
	marked[v] = true;
	Bag *TempBag = G.Iterator(v);
	TempBag->BeginIter();
	int iter;
	while(TempBag->HasNext())
		if(!marked[(iter = TempBag->Next())])
			dfs(G,iter);
}
Example #13
0
    void ShowTransmogItems(Player* player, Creature* creature, uint8 slot) // Only checks bags while can use an item from anywhere in inventory
    {
        WorldSession* session = player->GetSession();
        Item* oldItem = player->GetItemByPos(INVENTORY_SLOT_BAG_0, slot);
        if (oldItem)
        {
            uint32 limit = 0;
            uint32 price = sT->GetSpecialPrice(oldItem->GetTemplate());
            price *= sT->GetScaledCostModifier();
            price += sT->GetCopperCost();
            std::ostringstream ss;
            ss << std::endl;
            if (sT->GetRequireToken())
                ss << std::endl << std::endl << sT->GetTokenAmount() << " x " << sT->GetItemLink(sT->GetTokenEntry(), session);

            for (uint8 i = INVENTORY_SLOT_ITEM_START; i < INVENTORY_SLOT_ITEM_END; ++i)
            {
                if (limit > MAX_OPTIONS)
                    break;
                Item* newItem = player->GetItemByPos(INVENTORY_SLOT_BAG_0, i);
                if (!newItem)
                    continue;
                if (!sT->CanTransmogrifyItemWithItem(player, oldItem->GetTemplate(), newItem->GetTemplate()))
                    continue;
                if (sT->GetFakeEntry(oldItem->GetGUID()) == newItem->GetEntry())
                    continue;
                ++limit;
                player->ADD_GOSSIP_ITEM_EXTENDED(GOSSIP_ICON_MONEY_BAG, sT->GetItemIcon(newItem->GetEntry(), 30, 30, -18, 0)+sT->GetItemLink(newItem, session), slot, newItem->GetGUIDLow(), "Using this item for transmogrify will bind it to you and make it non-refundable and non-tradeable.\nDo you wish to continue?\n\n"+sT->GetItemIcon(newItem->GetEntry(), 40, 40, -15, -10)+sT->GetItemLink(newItem, session)+ss.str(), price, false);
            }

            for (uint8 i = INVENTORY_SLOT_BAG_START; i < INVENTORY_SLOT_BAG_END; ++i)
            {
                Bag* bag = player->GetBagByPos(i);
                if (!bag)
                    continue;
                for (uint32 j = 0; j < bag->GetBagSize(); ++j)
                {
                    if (limit > MAX_OPTIONS)
                        break;
                    Item* newItem = player->GetItemByPos(i, j);
                    if (!newItem)
                        continue;
                    if (!sT->CanTransmogrifyItemWithItem(player, oldItem->GetTemplate(), newItem->GetTemplate()))
                        continue;
                    if (sT->GetFakeEntry(oldItem->GetGUID()) == newItem->GetEntry())
                        continue;
                    ++limit;
                    player->ADD_GOSSIP_ITEM_EXTENDED(GOSSIP_ICON_MONEY_BAG, sT->GetItemIcon(newItem->GetEntry(), 30, 30, -18, 0)+sT->GetItemLink(newItem, session), slot, newItem->GetGUIDLow(), "Using this item for transmogrify will bind it to you and make it non-refundable and non-tradeable.\nDo you wish to continue?\n\n"+sT->GetItemIcon(newItem->GetEntry(), 40, 40, -15, -10)+sT->GetItemLink(newItem, session)+ss.str(), price, false);
                }
            }
        }

        player->ADD_GOSSIP_ITEM_EXTENDED(GOSSIP_ICON_MONEY_BAG, "|TInterface/ICONS/INV_Enchant_Disenchant:30:30:-18:0|tRemove transmogrification", EQUIPMENT_SLOT_END+3, slot, "Remove transmogrification from the slot?", 0, false);
        player->ADD_GOSSIP_ITEM(GOSSIP_ICON_MONEY_BAG, "|TInterface/PaperDollInfoFrame/UI-GearManager-Undo:30:30:-18:0|tUpdate menu", EQUIPMENT_SLOT_END, slot);
        player->ADD_GOSSIP_ITEM(GOSSIP_ICON_MONEY_BAG, "|TInterface/ICONS/Ability_Spy:30:30:-18:0|tBack..", EQUIPMENT_SLOT_END+1, 0);
        player->SEND_GOSSIP_MENU(DEFAULT_GOSSIP_MESSAGE, creature->GetGUID());
    }
Example #14
0
void Payer::delta_ext(double e, const Bag<IO>& xb)
{
	// Record the times at which the bene left the provider.
	Bag<IO>::const_iterator i;
	for (i = xb.begin(); i != xb.end(); i++)
	{
		//const Signal* c = (*i).value;
		total_number_of_patients += 1;
	}
}
Example #15
0
Bag Board::tilesNotOnBoard() const
{
	Bag ret;

	for (int row = 0; row < m_height; row++)
		for (int col = 0; col < m_width; col++)
			if (m_letters[row][col] != QUACKLE_NULL_MARK)
				ret.removeLetter(m_isBlank[row][col]? QUACKLE_BLANK_MARK : m_letters[row][col]);

	return ret;
}
Example #16
0
void test5()
{
	genr* g = new genr(10.0,10);
	Simulator<char> sim(g);
	Bag<Event<char> > input;
	Event<char> event(g,'a');
	input.insert(event);
	sim.computeNextState(input,5.0);
	assert(sim.nextEventTime() == DBL_MAX);
	assert(g->getTickCount() == 0);
	delete g;
}
Example #17
0
Digraph::Digraph(const Digraph& G) : V_(G.V_), E_(G.E_) {
	printf("Copying Digraph\n");
	adj_ = new Bag<int>[G.V_];
	for (int v = 0; v < G.V_; v++) {
		// reverse so that adjacency list is in the same order as original
		Bag<int> reverse;
		for (int w : G.adj_[v])
			reverse.add(w);
		for (int w : reverse)
			adj_[v].add(w);
	}		
}
Bag sort_descending(const Bag& b1)
{
	Bag sorted_bag;
	Bag temp = b1; // Since elements of b1 can't be altered, use copy of b1
	const int initial_size = temp.size();
	for (size_t i = 0; i < initial_size; ++i)
	{
		Student max = temp.find_max();
		sorted_bag.insert(max);
		temp.erase_one(max);
	}
	return sorted_bag;
}
Example #19
0
void DepthFirstOrder::dfs(DirGraph &G, int v){
	pre.push_back(v);
	marked[v] = true;
	Bag *Temp = G.Iterator(v);
	Temp->BeginIter();
	int nextVert;	
	while(Temp->HasNext()){
		nextVert = Temp->Next();
		if(!marked[nextVert])
			dfs(G,nextVert);
	}
	post.push_back(v);
	reversePost.push_front(v);	
}
Example #20
0
Bag* Bag::create()
{
	Bag *pRet = new Bag();
    if (pRet && pRet->init())
    {
        pRet->autorelease();
        return pRet;
    }
    else
    {
        CC_SAFE_DELETE(pRet);
        return NULL;
    }
}
Example #21
0
void partition_table::partition(MonomialIdeal * &I, array<MonomialIdeal *> &result)
  // consumes and frees I
{
  int k;
  reset(I->topvar()+1);
  // Create the sets
  for (Index<MonomialIdeal> i = I->first(); i.valid(); i++)
    if (n_sets > 1)
      merge_in((*I)[i]->monom().raw());
    else
      break;

  if (n_sets == 1)
    {
      result.append(I);
      return;
    }

  int this_label = -1;
  n_sets = 0;
  for (k=0; k<n_vars; k++)
    if (occurs[k] && dad[k] < 0)
      {
        dad[k] = this_label--;
        n_sets++;
      }

  if (n_sets == 1)
    {
      result.append(I);
      return;
    }

  int first = result.length();
  for (k=0; k<n_sets; k++)
    result.append(new MonomialIdeal(I->get_ring(), mi_stash));

  // Now partition the monomials
  Bag *b;
  while (I->remove(b))
    {
      const intarray &m = b->monom();
      int v = varpower::topvar(m.raw());
      int loc = -1-dad[representative(v)];
      result[first+loc]->insert_minimal(b);
    }

  delete I;
}
Example #22
0
void Computer::route(const SimEvent& value, Devs<SimEvent>* model,
                     Bag<Event<SimEvent> > &r)
{
    // Packets and interrupts go to the packet processing model
    if (value.getType() == SIM_PACKET || value.getType() == SIM_INTERRUPT)
        r.insert(Event<SimEvent>(&p,value));
    // Motor on times go to the interrupt handler
    else if (value.getType() == SIM_MOTOR_ON_TIME)
        r.insert(Event<SimEvent>(&i,value));
    // Motor voltages are external outputs
    else if (value.getType() == SIM_MOTOR_VOLTAGE)
        r.insert(Event<SimEvent>(this,value));
    // Any other type is an error
    else assert(false);
}
Example #23
0
void QueueBus::delta_ext(double e, const Bag<PortValue<BasicEvent*> >& xb)
{
	if (!q.empty()) ttg -= e;
	for (Bag<PortValue<BasicEvent*> >::const_iterator iter = xb.begin();
			iter != xb.end(); iter++)
	{
		if (q.empty()) schedule_next_packet();
		packet_t pkt;
		pkt.e = ((*iter).value);
		if (pkt.e != NULL) pkt.e = pkt.e->clone();
		// Goes out on the same port that it arrived from
		pkt.out_port = ((*iter).port);
		q.push_back(pkt);
	}
}
void test_bag::test_search()
{
  Bag<int> b;
  
  cout << endl << "test_search: Constructor check" << endl;
  CPPUNIT_ASSERT( b.size() == 0);
  
  cout << "test_search: Searching for character 3" << endl;
  b.push_back( 3 ); //0
  b.push_back( 4 ); //1
  b.push_back( 5 ); //2
  CPPUNIT_ASSERT (b.search(5) == 2);
  
  return;
}
Example #25
0
		void output_func(const double* q, const bool* event_flag,
				Bag<PortValue<double> >& yb)
		{
			assert(event_flag[0] || event_flag[1]);
			PortValue<double> event(0,q[0]);
			yb.insert(event);
		}
Example #26
0
void RealLocalGarbage::collectBag(Bag &bag) {
    for (auto f : bag) {
        f();
    }
    // XXX: should we shrink capacity?
    bag.clear();
}
void test_bag::test_pop_back()
{
  Bag<int> b;
  
  cout << endl << "test_pop_back: Constructor check" <<  endl;
  CPPUNIT_ASSERT( b.size() == 0 );
  
  b.push_back( 3 );
  b.push_back( 4 );
  
  cout << "test_pop_back: Pull one item off the bag" << endl;
  b.pop_back();
  CPPUNIT_ASSERT( b[1] == NULL );
  CPPUNIT_ASSERT( b[0] == 3 );
  
  return;
}
Example #28
0
void SaccadeMotorProgram::output_func(Bag<IO_Type>& yb)
{
	Saccade* s = _saccades.front();
	s->nonlabile_stop = _time + ta();
	IO_Type output(execute, s);
	yb.insert(output);
	//printf("%f\t    SaccadeMotorProgram: Non-labile programming complete\n", _time);
}
Example #29
0
int main()
{
    Bag<int> mBag;
    
    cout << "size: " << mBag.getSize() << endl;
    cout << "isEmpty(): " << mBag.isEmpty() << endl;
    cout << "adding 1,2,3...\n";
    mBag.add(1);
    mBag.add(2);
    mBag.add(3);
    cout << "size: " << mBag.getSize() << endl;
    cout << "isEmpty(): " << mBag.isEmpty() << endl << endl;
    cout << "Contents: " << mBag;
    Bag<int> mBag2;
    cout << "\nTesting equal operator: ";
    mBag2 = mBag;
    cout << mBag2 << endl;
    cout << "Testing copy constructor: ";
    Bag<int> mBag3(mBag2);
    cout << mBag3 << endl;
    
    cout << "\nTesting remove(2): ";
    mBag3.remove(2);
    cout << mBag3 << endl;
    
    cout << "\nTesting clear(): ";
    mBag3.clear();
    cout << mBag3 << endl;
    
    cout << "\nTesting contains(3): " << mBag2.contains(3) << endl;
    mBag2.contains(3);
    cout << mBag2 << endl;
    cout << "\nTesting contains(7): " << mBag2.contains(7) << endl;
    mBag2.contains(7);
    cout << mBag2 << endl;
    
    Bag<int> mBag4;
    mBag4.add(1);
    mBag4.add(2);
    mBag4.add(3);
    mBag4.add(4);
    mBag4.add(2);
    cout << "\nTesting getFrequency(2): " << mBag4.getFrequency(2) << endl;
    cout << "Bag contains: " << mBag4 << endl;
    
    Bag<int> test;
    cout << "\nTesting == operator test==bag4: " << (test == mBag4) << endl;
    cout << "Testing != operator test!=bag4: " << (test != mBag4) << endl;
    
    test += 1;
    cout << "Testing +=: contents " <<  test << endl;
    test += 33;
    cout << "Contents: " << test <<endl;
    
    cout << "Testing -=: contents " <<  test << endl;
    test -= 33;
    cout << "Contents: " << test <<endl;
    
    return 0;
}
Example #30
0
		void output_func(const double* q, const double* a, const bool* event_flag,
				Bag<double>& yb)
		{
			check_soln(q,a);
			double z[1];
			state_event_func(q,a,z);
			assert(fabs(z[0]) < 1E-5);
			yb.insert(q[0]*a[0]);
		}