Exemplo n.º 1
0
      bool   Problem::FindSuccessors(const ai::Search::State * const state_in,
                                     std::vector<ai::Search::ActionStatePair>
                                     &results_out) const
      {
        const State * const state = dynamic_cast<const State * const>(state_in);
        
        /* push each remaining number */
        std::set<double>::const_iterator sit;
        
        for(sit = state->GetUnused().begin();
            sit != state->GetUnused().end();
            sit++)
          {
            State  *new_state  = new State(*state);
            Action *new_action = new Action();
            
            new_state->PushStack(*sit);
            
            new_action->SetType(Action::A_PUSH_NUMBER);
            new_action->SetNumber(*sit);

            ai::Search::ActionStatePair asp(new_state, new_action);
            results_out.push_back(asp);
          }
        
        
        /* push each operator */
        if(state->GetStack().size() >= 2)
          {
            int op;
            for(op = (int)Action::O_MIN+1; op < (int)Action::O_MAX; op++)
              {
                State  *new_state  = new State(*state);
                Action *new_action = new Action();
                
                new_state->PushOperator(op);
                
                new_action->SetType(Action::A_PUSH_OPERATOR);
                new_action->SetOperator(op);
                
                ai::Search::ActionStatePair asp(new_state, new_action);
                results_out.push_back(asp);
              }
          }
        return (results_out.size() > 0);
      }
Exemplo n.º 2
0
void init(void)
{
	pack_data data;

	if(load_pack(&data,"shaders.bin"))
	{
		set_global_pack(&data);

		if(init_model_vbo() && init_text_pro())
		{
			mat4 proj, view;

			glClearColor(0.02f,0.0f,0.02f,1.0f);

			persp(proj,75.0f,asp(),1.0f,20.0f);
			look(view,v3(0.0f,0.0f,1.7f),v3(-1.0f,0.0f,1.7f));
			mult(pview,proj,view);

			done_pack(&data);
			if(load_pack(&data,"assets.bin"))
			{
				if(load_model(&area_mod,"area-mod.bin"))
				{
					gen_texs(1,&area_tex);
					if(load_tex_compressed(area_tex,"area-tex.bin",tf_mipmap))
					{
						use_basic();
						basic_texmode(1);

						use_text_pro();
						text_instanced(1);

						if(load_font(&font,"sans-fontmap.bin","sans-fontdata.bin"))
							init_text(&text,10.0f,10.0f,"Demo scene");
						else quit();
					}
					else quit();
				}
				else quit();
			}
			else quit();
		}
		else quit();

		set_global_pack(NULL);
		done_pack(&data);
	}
	else quit();
}
Exemplo n.º 3
0
int main()
{
    try
    {
        AeroSerialPort asp("/dev/ttyACM0");
        
        for (int i=1300; i>1200; i-=5)
        {
            char buf[100];

            sprintf(buf, "5123.45;%i;%i;%i;%i;", i, i, i, i);
            asp.writeString(std::string(buf));

            std::this_thread::sleep_for(std::chrono::milliseconds(250));

        }
        asp.writeString("4\r");
    }
    catch (AeroSerialPort::SerialPortException e)
    {
        std::cout << e.what() << std::endl;
    }

}
Exemplo n.º 4
0
int main()
{
//    cpu_set_t cpus;
//    CPU_ZERO(&cpus);
//    CPU_SET(0, &cpus);
//    int rc0 = sched_setaffinity(0, sizeof(cpus), &cpus);
//    TRACE << "ssa returned " << rc0 << "\n";

    util::MemoryStream ms;

    util::WorkerThreadPool wtp(util::WorkerThreadPool::NORMAL);
    util::AsyncWriteBuffer asp(&ms, &wtp);
    TestSeekableStream(&asp);

    std::unique_ptr<util::Stream> fsp;

    unsigned int rc = util::OpenFileStream("test2.tmp", util::TEMP, &fsp);
    assert(rc == 0);

    util::AsyncWriteBuffer asp2(fsp.get(), &wtp);
    TestSeekableStream(&asp2);

    return 0;
}
Exemplo n.º 5
0
int Umeyama(const gsl_matrix * const A,
            const gsl_matrix * const B,
            gsl_matrix * const Assignment,
            float *score)
{
	int res = 0;
	gsl_matrix_complex *AE = NULL, *BE = NULL;
	gsl_matrix	*P  = NULL,
			*AS = NULL,
			*BS = NULL,
			*AN = NULL,
			*BN = NULL,
			*AssignmentT = NULL;
	#ifdef USE_ASP
	long *col_mate;
	long *row_mate;
	cost **pTempCost;
	int i, j;
	#endif
	struct timeval start, end;
	long mtime, seconds, useconds;

	#ifdef VERBOSE
	PrintGSLMatrix(A, "Umeyama A");
	PrintGSLMatrix(B, "Umeyama B");
	#endif

	AE = gsl_matrix_complex_alloc(A->size1, A->size2);	if(AE == NULL) goto _exit;
	AS = gsl_matrix_alloc(A->size1, A->size2);		if(AS == NULL) goto _exit;
	AN = gsl_matrix_alloc(A->size1, A->size2);		if(AN == NULL) goto _exit;
	ComputeHermitianMatrix(A, AE, AS, AN);
	#ifdef VERBOSE
	PrintGSLMatrix(AS, "AS");
	PrintGSLMatrix(AN, "AN");
	#endif
	if( IsHermitian(AE) == false )
	{
		fprintf(stderr, "FATAL: AE is not Hermitian!\n");
		exit(0);
	}
	#ifdef VERBOSE
	fprintf(stderr, "Verified AE is Hermitian.\n");
	#endif

	BE = gsl_matrix_complex_alloc(B->size1, B->size2);	if(BE == NULL) goto _exit;
	BS = gsl_matrix_alloc(B->size1, B->size2);		if(BS == NULL) goto _exit;
	BN = gsl_matrix_alloc(B->size1, B->size2);		if(BN == NULL) goto _exit;
	ComputeHermitianMatrix(B, BE, BS, BN);
	#ifdef VERBOSE
	PrintGSLMatrix(BS, "BS");
	PrintGSLMatrix(BN, "BN");
	#endif
	if( IsHermitian(BE) == false )
	{
		fprintf(stderr, "FATAL: BE is not Hermitian!\n");
		exit(0);
	}
	#ifdef VERBOSE
	fprintf(stderr, "Verified BE is Hermitian.\n");
	WriteComplexMatrixToFile(BE);
	PrintGSLMatrixComplex(AE, "AE");
	PrintGSLMatrixComplex(BE, "BE");
	#endif
	
	P = gsl_matrix_alloc(A->size1, A->size2);		if(P == NULL) goto _exit;
	res = EigenDecomp(AE, BE, P);
	if( res == -1 ) goto _exit;
	#ifdef VERBOSE
	PrintGSLMatrix(P, "P");
	PrintGSLMatrix(P, "Computing Hungarian");
	#endif

	// Begin timing Hungarian
	gettimeofday(&start, NULL);
	#ifdef USE_ASP
	col_mate = new long[P->size1];
	row_mate = new long[P->size1];

	pTempCost = new cost*[P->size1];
	for(i = 0; i < P->size1; ++i)
		pTempCost[i] = new cost[P->size2];

	for(i = 0; i < P->size1; ++i)
		for(j = 0; j < P->size2; ++j)
			pTempCost[i][j] = gsl_matrix_get(P, i, j);

	asp(P->size1, pTempCost, col_mate, row_mate);

	for(i = 0; i < P->size1; ++i)
		delete[] pTempCost[i];
	delete[] pTempCost;

	// Update assignment matrix
	for(i = 0; i < P->size1; ++i)
		gsl_matrix_set(Assignment, i, col_mate[i], 1);

	delete[] col_mate;
	delete[] row_mate;

	#else
	Hungarian(P, true, Assignment);
	#endif
	// End timing Hungarian
	gettimeofday(&end, NULL);
	seconds = end.tv_sec - start.tv_sec;
	useconds = end.tv_usec - start.tv_usec;
	mtime = ((seconds) * 1000 + useconds/1000.0) + 0.5;
	fprintf(stderr, "%ld ms\t", mtime);

	// PrintGSLMatrixUint(Assignment, "Assignment");

	// Allocate and initialize AssgtT
	AssignmentT = gsl_matrix_alloc(Assignment->size1, Assignment->size2);
	if(AssignmentT == NULL) goto _exit;
	gsl_matrix_memcpy(AssignmentT, Assignment);
	gsl_matrix_transpose(AssignmentT);

	/*
	PrintGSLMatrix(AS, "AS");
	PrintGSLMatrix(AN, "AN");
	PrintGSLMatrix(BS, "BS");
	PrintGSLMatrix(BN, "BN");
	*/
	*score = CalcScore(AS, AN, BS, BN, Assignment, AssignmentT);

_exit:
	if(P != NULL)		gsl_matrix_free(P);
	if(AS != NULL)		gsl_matrix_free(AS);
	if(AN != NULL)		gsl_matrix_free(AN);
	if(BS != NULL)		gsl_matrix_free(BS);
	if(BN != NULL)		gsl_matrix_free(BN);
	if(AE != NULL)		gsl_matrix_complex_free(AE);
	if(BE != NULL)		gsl_matrix_complex_free(BE);
	if(AssignmentT != NULL)	gsl_matrix_free(AssignmentT);

	return res;
}
Exemplo n.º 6
0
 void VoidInvoke(Func&& f, Args&&... args)
 {
     AspectUtils<Func, Args...> asp(std::forward<Func>(f));
     asp.VoidInvoke(std::forward<Args>(args)..., identity_t<AP>()...);
 }
Exemplo n.º 7
0
 void MemberVoidInvoke(T* pObj, Func pFunc, Args&&... args)
 {
     MemberAspectUtils<T, Func, Args...> asp(pObj, pFunc);
     asp.VoidInvoke(std::forward<Args>(args)..., identity_t<AP>()...);
 }
Exemplo n.º 8
0
void invoke(Func&& fn, TArgs&&... args){
    aspect<Func, TArgs...> asp(std::forward<Func>(fn));
    asp.invoke(std::forward<TArgs>(args)..., identity_t<AP>()...);
};
Exemplo n.º 9
0
int main(int argc, char *argv[])
{
	int N,E;
	int **ppAdjMat;
	int **ppNext;
	char szFileName[MAX_PATH];

	int totalDistance;
	int diameter;

	double elapsedTime;
	struct timezone tz;
	struct timeval End;
	struct timeval Start;

	int PrintPath = 0;

	if (argc < 0 || argc > 3)
	{
		printf("Usage: asp <path of road_list> [p]\n");
		printf("p : Paths will be generated in file\n");
		return 0;
	}

	if (strlen(argv[1]) >= MAX_PATH)
	{
		printf("File name too long.\n");
		return 1;
	}

	if (argc > 2)
	{
	  if (argv[2][0] == 'p' || argv[2][0] == 'P')
	  {
	    PrintPath = 1;
	  }
	  else
	  {
		printf("Invalid option\n");
		return 0;
	  }
	}

	strcpy(szFileName, argv[1]);
	N = 0;
	E = 0;
	ppAdjMat = NULL;
	ParseFile(szFileName, &N, &E, &ppAdjMat, &ppNext);

	memset(&Start, 0L, sizeof(struct timeval));
	memset(&End, 0L, sizeof(struct timeval));
	memset(&tz, 0L, sizeof(struct timezone));
	gettimeofday(&Start, &tz);

	totalDistance =	calculate_total_road_distance(ppAdjMat, N, N);
	asp(ppAdjMat, ppNext,N);
	diameter = calculate_diameter(ppAdjMat, N, N);

	gettimeofday(&End, &tz);

	elapsedTime = (End.tv_sec - Start.tv_sec) * 1000.0;
	elapsedTime += (End.tv_usec - Start.tv_usec) / 1000.0;

	printf("File name:<%s>\n", szFileName);
	printf("Number of vertices = %d\n", N);
	printf("Total road distance = %d\n", totalDistance/2);
	printf("Diameter = %d\n", diameter);
	printf("%s %f milliseconds\n", "Total time = ", elapsedTime);

	PrintAdjMatToFile(OUTPUT_FILE, ppAdjMat, N, N);
	if (PrintPath == 1)
	{
	  PrintPathsToFile(PATH_OUTPUT_FILE, ppAdjMat, ppNext, N, N);
	}

	FreeGraph(ppAdjMat, N);
	return 0;
}
Exemplo n.º 10
0
Arquivo: app.c Projeto: youka2/fx
void init(void)
{
	if(init_mblur() && init_vig() && init_quad())
	{
		int size=0; void *data=NULL;

		/*glClearColor(1.0f,1.0f,1.0f,1.0f);*/
		glClearColor(0.04f,0.0f,0.04f,1.0f);

		use_mblur();
		send_mblur_samples(16.0f); /* adjust motion blur samples here */

		use_vig();
		send_vig_size((float)sw(),(float)sh());
		vigmode(0);

		use_basic();
		persp(proj,75.0f,asp(),0.1f,24.0f);

		if(fload("data/area-model.bin",&size,&data))
		{
			add_to_vbo(&area_mod,data,size);
			free(data);

			update_vbo();

			gen_texs(1,&area_tex);
			//if(load_tex_compressed(area_tex,"data/area-ao-texture.bin",tf_mipmap))
			if(load_tex_compressed(area_tex,"data/area-texture.bin",tf_mipmap))
			{
				const int downsample=1; /* adjust fb down-sizing here */
				texmode(1);

				nsw=sw()/downsample;
				nsh=sh()/downsample;

				gen_texs(4,texs);
				gen_rbs(3,rbs);
				gen_fbs(4,fbos);

				use_fb(fbos[0]);
				add_fb_rb(0,rbs[0],nsw,nsh,GL_RGB8,4); /* adjust renderbuffer samples here */
				add_fb_rb(0,rbs[1],nsw,nsh,GL_DEPTH_COMPONENT24,4); /* adjust renderbuffer samples here */

				use_fb(fbos[1]);
				add_fb_tex(0,texs[0],nsw,nsh,GL_RGB8,tf_linear);
				add_fb_rb(0,rbs[2],nsw,nsh,GL_DEPTH_COMPONENT24,0);

				use_fb(fbos[2]);
				add_fb_tex(0,texs[1],nsw,nsh,GL_RGB8,tf_linear);
				add_fb_tex(1,texs[2],nsw,nsh,GL_RGBA32F,tf_linear);
				add_fb_rb(0,rbs[2],nsw,nsh,GL_DEPTH_COMPONENT24,0);

				use_fb(fbos[3]);
				add_fb_tex(0,texs[3],nsw,nsh,GL_RGB8,tf_linear);

				use_fb(0);
				use_rb(0);
				use_tex(0);
			}
			else quit();
		}
		else quit();
	}
	else quit();
}
Exemplo n.º 11
0
static PyObject *
hungarian(PyObject *self, PyObject *args)
//hungarian(costs)
{
  PyObject *ocosts;
  PyArrayObject *costs;
  int n;
  npy_intp n2;
  long *rowsol;
  long *colsol;
  cost *buf,**ccosts;
  npy_intp *strides;
  PyObject * rowo;
  PyObject * colo;

  if (!PyArg_ParseTuple(args, "O", &ocosts))
    return NULL;
  costs = (PyArrayObject*)PyArray_FromAny(
                                          ocosts,PyArray_DescrFromType(COST_TYPE_NPY),2,2,
                                          NPY_CONTIGUOUS|NPY_ALIGNED|NPY_FORCECAST,0
                                          );

  if (costs->nd!=2)
    {
      PyErr_SetString(PyExc_ValueError,"lap() requires a 2-D matrix");
      goto error;
    }
  n = costs->dimensions[0];
  n2 = costs->dimensions[0];
  if (costs->dimensions[1]!=n)
    {
      PyErr_SetString(PyExc_ValueError,"lap() requires a square matrix");
      goto error;
    }

  //get inputted matrix as a 1-D C array:
  buf = (cost*)PyArray_DATA(costs);

  //copy inputted matrix into a 2-dimensional C array:
  strides = PyArray_STRIDES(costs);
  assert(strides[1] == sizeof(cost));
  ccosts = (cost **)malloc(sizeof(cost *)*n);
  if(!ccosts)
    {
      PyErr_NoMemory();
      free(ccosts);
      goto error;
    }
  for(int i=0;i<n;i++)
    ccosts[i] = buf+i*(strides[0]/sizeof(cost));

  //allocate data for the output array
  rowo = PyArray_SimpleNew(1, &n2, NPY_LONG);
  colo = PyArray_SimpleNew(1, &n2, NPY_LONG);
  rowsol = (long *) PyArray_DATA(rowo);
  colsol = (long *) PyArray_DATA(colo);
  if(!(rowsol&&colsol))
    {
      PyErr_NoMemory();
      free(ccosts);
      goto error;
    }

  //run hungarian!:
  asp(n,ccosts,rowsol,colsol);

  //NA_InputArray() incremented costs, but now we're done with it, so let it get GC'ed:
  Py_XDECREF(costs);

  free(ccosts);
  return Py_BuildValue("(NN)",
                       rowo, colo
                       );
 error:
  Py_XDECREF(costs);
  return NULL;
}