Exemplo n.º 1
0
void CSimpleBattery::TimeElapse(double time, double timeElapsed)
{
	if( _portCurrent < 0 ) {
		_consumption += Discharge(timeElapsed,-_portCurrent);
	}
	else if( _portCurrent > 0 ) {
		_consumption -= Charge(timeElapsed,_portCurrent);
	}
}
void HospitalizationManagement::initUI()
{
    Registry();
    Pay();
	Charge();
	Discharge();
	InternalPayment();
	Dailyreport();
	Statistics();
}
Exemplo n.º 3
0
  void MessageDispatcher::DispatchDelayedMessage()
  {
    boost::posix_time::ptime curTime(boost::posix_time::microsec_clock::local_time());
    while(!msgQ_.empty() && msgQ_.top().dispatchTime_ <= curTime)
      {
	Telegram msg = msgQ_.top();
	msgQ_.pop();
	BaseGameEntity* pReceiver = EntityManager::Instance().GetEntityFromID<BaseGameEntity>(msg.receiverID_);
	Discharge(pReceiver, msg);
      }
  }
Exemplo n.º 4
0
// DispatchMessage function: sends the message to Discharge if it has no delay, otherwise puts it in the PriorityQ
void MessageDispatcher::DispatchMessage(float fDelay, int iSender, int iReceiver, int iMsg)
{
	// Get a pointer to the Entity that is receiving the message
	Entity* pReceiver = EntityManager::Instance()->GetEntityFromID(iReceiver);

	// create the message
	Message Msg(iSender, iReceiver, iMsg, fDelay);

	// if no delay, route the message immediately
	if(fDelay <= 0.0f)
		Discharge(pReceiver, Msg);
	else // otherwise add the current time the delay and insert message into PriorityQ
	{
		float fCurrentTime = Timer::Instance()->GetCurrentTime();

		Msg.m_fDispatchTime = fCurrentTime + fDelay;

		m_PriorityQ.insert(Msg);
	}
}
Exemplo n.º 5
0
  void MessageDispatcher::DispatchMessage(boost::posix_time::time_duration delay
					  ,int senderID, int receiverID, int type, boost::any data)
  {
    BaseGameEntity* pSender = EntityManager::Instance().GetEntityFromID<BaseGameEntity>(senderID);
    BaseGameEntity* pReceiver = EntityManager::Instance().GetEntityFromID<BaseGameEntity>(receiverID);
    if(pSender==0 || pReceiver==0)
      return;

    if(delay <= boost::posix_time::milliseconds(33))
      {
	Telegram msg(boost::posix_time::microsec_clock::local_time(),senderID,receiverID,type,data);
	Discharge(pReceiver, msg);
      }
    else
      {
	boost::posix_time::ptime t(boost::posix_time::microsec_clock::local_time());
	Telegram msg(t+delay, senderID, receiverID, type, data);
	msgQ_.push(msg);
      }
  }
    LL GetMaxFlow(int s, int t) {
        count[0] = N-1;
        count[N] = 1;
        dist[s] = N;
        active[s] = active[t] = true;
        for (int i = 0; i < G[s].size(); i++) {
            excess[s] += G[s][i].cap;
            Push(G[s][i]);
        }

        while (!Q.empty()) {
            int v = Q.front();
            Q.pop();
            active[v] = false;
            Discharge(v);
        }

        LL totflow = 0;
        for (int i = 0; i < G[s].size(); i++) totflow += G[s][i].flow;
        return totflow;
    }
Exemplo n.º 7
0
// DispatchDelayedMessages function: loops through PriorityQ until empty or there are no messages to be dispatched at current time
void MessageDispatcher::DispatchDelayedMessages()
{
	// get the current time
	float fCurrentTime = Timer::Instance()->GetCurrentTime();

	while((!m_PriorityQ.empty()) &&
		(m_PriorityQ.begin()->m_fDispatchTime < fCurrentTime) &&
		(m_PriorityQ.begin()->m_fDispatchTime > 0.0f))
	{
		// copy the first message in the priorityQ
		Message Msg = *m_PriorityQ.begin();

		// get the receiving Entity
		Entity* pReceiver = EntityManager::Instance()->GetEntityFromID(Msg.m_iReceiver);

		// send the message to that Entity
		Discharge(pReceiver, Msg);

		// erase the message from the PriorityQ
		m_PriorityQ.erase(m_PriorityQ.begin());
	}
}
Exemplo n.º 8
0
void cTplCoxRoyAlgo<cCRNode>::EndMaxFlowStd(int aX0,int aY0,int aX1,int aY1)
{
        mX0Loc = aX0;
        mY0Loc = aY0;
        mX1Loc = aX1;
        mY1Loc = aY1;

       SetFlagEdges(mX0Loc,mY0Loc,mX1Loc,mY1Loc,false);


	// Init();
	/** flood the first nodes **/
	for(int anY=mY0Loc ; anY<mY1Loc ; anY++)
        {
	    for(int anX=mX0Loc ; anX<mX1Loc ; anX++) 
            {
                 cCRNode *  aCol = ColumnOfP(anX,anY);
		 int  aZ0 = ZMin(anX,anY);
		 int  aZ1 = ZMax(anX,anY);
		 for (int aZ = aZ0; (aZ<aZ1) && (aCol[aZ].SourceConnected()) ; aZ++)
                 {

                     aCol[aZ].SetExcess(largef);
		     mCRH.LinkQInsert(cRoyPt(anX,anY,aZ),aCol[aZ].Height());
                 }
	    }
        }
	ResizeDetected=false;

        // End Init()



	int Level=mCRH.MaxKey();
        int Count =0;

	// printf("Starting at Key=%d\n",Level);

	/** generic preflow-push **/
	for(;;) 
        {
		/** This is the schedule for relabelling **/
		/** it can be changed for more/less relabel steps **/
		if( ((Count+1)%(2*sz/2)==0 && mSinkFlow!=0) || ResizeDetected ) 
		  {
			relabel();
			Level=mCRH.MaxKey();
			ResizeDetected=false;
		}

		/** update level to a non empty key **/
        mCRH.Set2NonEmptyKey(Level);

		/* if reached bottom, reset to top */
		if( Level<0 ) Level=mCRH.MaxKey(); /* highest level */

		/* if Level still <0 -> list MUST be empty! */
		if( Level<0 ) break; /* no more nodes! */

		/** get overflowing node with largest level **/
		cRoyPt aPU = mCRH.LinkQRemove(Level);

//		if( Count%100000==0 ) 
//		{
//        	mCRH.ShowLink();
			// printf("%6dk... SinkFlow=%8d  \n",Count/1000,mSinkFlow);
//		}

		Discharge(aPU);

		Count++;
	}

	// printf("SinkFlow=%d\n",mSinkFlow);
}