예제 #1
0
	virtual void onIterationStart() {
		// Only need to do this once
		rA = right->A( nextTime() );
		rb = right->b( nextTime() );
		lA =  left->A( nextTime() );
		lb =  left->b( nextTime() );

		// Evaluate the predicate using the previous iterand
		Vector predicate = rA * iterand(0) - rb;

		Vector compare = domain->zero();
		if(direct) {
			compare = lA * iterand(0) - lb;
		}

		// Initialize penalty matrix
		P.setZero();
		P.reserve( IntegerVector::Constant( domain->size(), 1 ) );

		// Initialize other matrix
		Q.setZero();
		Q.reserve( IntegerVector::Constant( domain->size(), 1 ) );

		// Build penalty matrix
		for(Index i = 0; i < domain->size(); ++i) {
			const bool c = Order()(
				(scale * predicate(i)),
				compare(i)
			);
			if(c) { P.insert(i, i) = scale; }
			if(!direct || !c) { Q.insert(i, i) = 1.; }
		}
	}
예제 #2
0
	virtual Matrix A(Real t) {
		assert(t == nextTime());

		#ifdef QUANT_PDE_MODULES_HJBQVI_ITERATED_OPTIMAL_STOPPING
		if(right_explicit) {
			return Q * lA + P;
		}
		#endif

		return Q * lA + P * rA;
	}
예제 #3
0
	virtual Vector b(Real t) {
		assert(t == nextTime());

		#ifdef QUANT_PDE_MODULES_HJBQVI_ITERATED_OPTIMAL_STOPPING
		if(right_explicit) {
			Matrix M = -(rA - domain->identity());
			return Q * lb + P * (rb + M * iterand(0));
		}
		#endif

		return Q * lb + P * rb;
	}
예제 #4
0
void CalculationThread::run() {
    qDebug() << "run called";
    nextTimeTimer = new QTimer;

    QObject::connect(nextTimeTimer, SIGNAL(timeout()), this, SLOT(nextTime()));

    nextTimeTimer->setInterval(10);
    nextTimeTimer->start();

    fromStartOfGame.start();

    exec();
}
void CActionHistory::OnPaint ()
{
  CPaintDC dc (this);
//  if (gl->isOk ())
//  {
//    gl->begin ();
  DCPaint dcp (&dc);
  CRect rc;
  GetClientRect (rc);
  ::FillRect (dc.m_hDC, &rc, (HBRUSH) GetStockObject (WHITE_BRUSH));
  dcp.setColor (0, 0, 0);
  if (w3g && pid >= 0 && agraphmx)
  {
    int id = w3g->players[pid].index;
    dcp.line (30, 0, 30, rc.bottom - 20);
    dcp.line (30, rc.bottom - 20, rc.right, rc.bottom - 20);
    for (int i = 0; i < agraph.getSize (); i++)
    {
      dcp.line (30 + i * BUCKET, rc.bottom - 20, 30 + i * BUCKET,
        rc.bottom - 20 - (rc.bottom - 30) * agraph[i] / agraphmx);
    }
    double sy = double (rc.bottom - 30) / double (agraphmx);
    double sx = double (rc.right - 30) / double (w3g->players[pid].time);

    EnumStruct es;
    enumCount (es);
    while (double (es.val) * sy < 15)
      nextCount (es);
    int cury = rc.bottom - 20;
    int stepy = int (double (es.val) * sy + 0.5);
    for (int i = 0; i <= agraphmx + es.val; i += es.val, cury -= stepy)
      dcp.drawText (28, cury, mprintf ("%d", i), ALIGN_Y_CENTER | ALIGN_X_RIGHT);

    enumTime (es);
    while (double (es.val) * sx < 40)
      nextTime (es);
    int curx = 30;
    int stepx = int (double (es.val) * sx + 0.5);
    int _start = w3g->game.startTime;
    for (unsigned long i = _start - (_start / es.val) * es.val; i < w3g->time; i += es.val)
    {
      int curx = 30 + int (double (i) * sx + 0.5);
      dcp.drawText (curx, rc.bottom - 15, format_time (w3g, i, TIME_HOURS | TIME_SECONDS), ALIGN_X_CENTER | ALIGN_Y_TOP);
    }
  }
//    gl->end ();
//  }
}
예제 #6
0
	void drawVRules(int start, int end)
	{
		EnumStruct es;
		enumTime(es);
		while (maph(es.val) < 50)
			nextTime(es);

		int offset = 0;
		if (cfg.relTime && w3g && w3g->getDotaInfo())
			offset = w3g->getDotaInfo()->start_time;
		for (int x = ((start - offset) / es.val - 1) * es.val + offset; x < end + es.val; x += es.val)
		{
			for (int sx = x - es.val + es.sub; sx < x; sx += es.sub)
				drawVRule(sx, NULL);
			drawVRule(x, w3g ? w3g->formatTime(x) : format_time(x));
		}
	}
double SolutionQueue::ta(){
	double nt = nextTime(solutionlist.size()) - t;
	return nt;
}
예제 #8
0
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
	static HDC hdcMem;					// offScreen для двойной буфферизации
	static HBITMAP hbmMem;              // тут хранится полное изображение на контексте
	static HANDLE hOld;                 // тут старый вид окна

	static PAINTSTRUCT ps;
	static HDC hdc;

	static int gameStat;				// Состояние игры. 0 -> идет. 1 -> победа. -1 -> проигрыш
	static int seconds;					// Секунды от страта таймера

	/// магия
	static bool newOffScreenDC = true;	// Флаг создания нового буффера для двойной буфферизации

	switch (message)
	{
	case WM_PAINT:
	{
					 RedrawField(hdcMem);

					 hdc = BeginPaint(hWnd, &ps);
					 BitBlt(hdc, 0, 0, SellSize * width, SellSize * height, hdcMem, 0, 0, SRCCOPY);
					 EndPaint(hWnd, &ps);

	}	break;
	//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
	case WM_TIMER:
	{
					 seconds = nextTime();
					 RedrawField(hdcMem);
					 hdc = GetDC(hWnd);
					 BitBlt(hdc, 0, 0, SellSize * width, SellSize * height, hdcMem, 0, 0, SRCCOPY);
					 ReleaseDC(hWnd, hdc);

					 if (seconds == 0)
					 {
						 KillTimer(hWnd, 1);
					 }

	}	break;
	//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
	case WM_LBUTTONUP:
	{
						 // Определяем ячейку
						 int j = LOWORD(lParam) / SellSize;		// j - ячейка по x
						 int i = HIWORD(lParam) / SellSize; 		// i - ячейка по y

						 if (i >= 0 && j >= 0 && i < height  && j < width) // Координаты попадают в поле
						 {
							 field[i][j].value = true;
							 RedrawField(hdcMem);

							 hdc = GetDC(hWnd);
							 BitBlt(hdc, 0, 0, SellSize * width, SellSize * height, hdcMem, 0, 0, SRCCOPY);
							 ReleaseDC(hWnd, hdc);
						 }
	}	break;
	//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

	case WM_COMMAND:
	{
					   if (wParam == ID_OPTIONS) // Открыть дочернее окно с параметрами
					   {
						   EnableWindow(hWndMain, FALSE); // Делаем неактивным главное окно

						   InitOptionWindow(); // Создаем окно. Если надо пересоздать поле CreateField -> true

						   if (CreateField)
						   {
							   KillTimer(hWnd, 1); // Сбрасиваем таймер
							   SetWindowPos(hWnd, HWND_TOP, 0, 0, SellSize * width + sizeOfBorder, SellSize * height + sizeOfMenuBar, SWP_SHOWWINDOW | SWP_NOMOVE);
							   InvalidateRect(hWnd, NULL, FALSE);	// Перерисовываем
						   }
						   //SetTimer(hWndMain, 1, 5000, NULL);
					   }
					   else if (wParam == ID_NEW)
					   {
						   KillTimer(hWnd, 1); // Сбрасиваем таймер
						   clearField();
						   InvalidateRect(hWnd, NULL, FALSE); // Перерисовываем
					   }
					   else if (wParam == ID_START)
					   {
						   SetTimer(hWndMain, 1, 1000, NULL);
					   }
	}	break;

	//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
	case WM_SIZE: // При изменении размера создаем off-screen DC
	{
					  /// эта магия для того чтоб при сворачивании мы заново не рисовали окно а пользовались старой отрисовкой

					  if (wParam == SIZE_MINIMIZED) // Не создаем нового экрана gосле минимизации
					  {
						  newOffScreenDC = false;
					  }
					  else if (wParam == SIZE_RESTORED && newOffScreenDC)
					  {
						  hdc = GetDC(hWnd);
						  hdcMem = CreateCompatibleDC(hdc);
						  hbmMem = CreateCompatibleBitmap(hdc, SellSize * width, SellSize * height);
						  hOld = SelectObject(hdcMem, hbmMem);
						  ReleaseDC(hWnd, hdc);

						  SetBkColor(hdcMem, RGB(249, 128, 182)); // Черный фон
						  newOffScreenDC = true;
					  }
					  else
					  {
						  newOffScreenDC = true;
					  }
	}	break;
	//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
	case WM_DESTROY: // При закрытии освобождаем память
	{
						 SelectObject(hdcMem, hOld);
						 DeleteObject(hbmMem);
						 DeleteDC(hdcMem);

						 PostQuitMessage(0);
	}	break;
	//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
	default:
		return DefWindowProc(hWnd, message, wParam, lParam);
	}

	return 0;
}
예제 #9
0
int main(void) {


	int N, run ; float avgC ;

	struct timeval startT, nowT, Wasingtime;
	sem_t WashMachine, Queue;

	int  pid = getpid(), CarId;

    printf("enter num of wash station(1-5):\nnum of run time program(in seconds)\nnum of avg arrival car to station:\n");
	scanf("%d%d%f", &N,&run,&avgC);


	 sem_init(&Queue, 1, 1);
	 sem_init(&WashMachine, 1, N);

	/////////////////Shared memory inition/////////////////////
	cars = (int*)SharedMemory(sizeof(int), 7);
	size = (int*)SharedMemory(sizeof(int), 5);
	washedcars = (int*)SharedMemory(sizeof(int), 51);
	timeWash = (double*)SharedMemory(sizeof(double), 75);
	(*size) = 0;
	*washedcars = 0;
	*timeWash = 0;
	//////////////////////////////////////////////////////////

	gettimeofday(&startT, NULL);
	//------------------START---------------------------------
	while ( GetTime(startT, UpdateTime(nowT))<=run)
	{

		if (pid == getpid())
		{
			if ((CarId=fork())!= 0)///case father- enter new car to Queue
			{

                sem_wait(&Queue);
				push(cars, size, CarId);
				printf("\nIm: %d {{Enterd to Queue}} in time: %lf\n", CarId, GetTime(startT, UpdateTime(nowT)));
				sem_post(&Queue);

				usleep((int)(pow(10,6)*nextTime(1.0/avgC))*-1);

            }
			else///case son-exit himself from Queue and enter to wash
			{

				signal(SIGQUIT, Quitpid);
				signal(SIGUSR1, EndWash);

                    sem_wait(&Queue);
                    if (cars[0] == getpid() )
					{

						sem_wait(&WashMachine);////////
                        pop(cars, size);//////////////  critical section
						sem_post(&Queue);/////////////
						gettimeofday(&Wasingtime, NULL);
						printf("Im: %d Enter to wash in time: %lf\n", getpid(), GetTime(startT, UpdateTime(nowT)));
						usleep((int)(pow(10, 6) * nextTime(1.0 / 3.0)*-1));
						sem_post(&WashMachine);
						printf("Im: %d Finish wash in time: %lf\n", getpid(), GetTime(startT, UpdateTime(nowT)));
						*timeWash += GetTime(Wasingtime, UpdateTime(nowT));
						*washedcars += 1;
						if(*size>0)
						kill(CarId, SIGUSR1);
						kill(getpid(), SIGQUIT);


                    }
		         else
					{
						sem_post(&Queue);
						pause();
					}
			}

		 }
		else
			break;

    }

	if(GetTime(startT, UpdateTime(nowT))>run+0.5)
	{
		printf("\n--------------------------After Time Ended---------------------\n");
		while((*size)>0)
		{
			 int temp=pop(cars, size);

	    gettimeofday(&Wasingtime, NULL);
		printf("Im: %d Enter to wash in time: %lf\n", temp, GetTime(startT, UpdateTime(nowT)));
        usleep((int) (pow(10, 6) * nextTime(1.0 / 3.0))*-1);
		printf("Im: %d Finish wash in time: %lf\n", temp, GetTime(startT, UpdateTime(nowT)));
		*timeWash += GetTime(Wasingtime, UpdateTime(nowT));
	    *washedcars += 1;

		}


    printf("\n\n{End program}\n");
	printf("car washed--> [%d] in Total run Time: %lf\n", *washedcars, GetTime(startT, UpdateTime(nowT)));
	printf("avg wash time: %lf(s)\n", *timeWash / (*washedcars));
	}



	return EXIT_SUCCESS;
}