Exemplo n.º 1
0
void Mover::update()
{
    velocity += acceleration;
    location += velocity;
    checkEdges();
    acceleration = Vec2f::zero();
}
static void checkIsValidReference(CuTest *testCase, stList *reference,
        double totalScore) {
    stList *chosenEdges = convertReferenceToAdjacencyEdges(reference);
    //Check that everyone has a partner.
    CuAssertIntEquals(testCase, nodeNumber, stList_length(chosenEdges) * 2);
    stSortedSet *nodes = stSortedSet_construct3((int(*)(const void *, const void *)) stIntTuple_cmpFn,
            (void(*)(void *)) stIntTuple_destruct);
    for (int64_t i = 0; i < nodeNumber; i++) {
        stSortedSet_insert(nodes, stIntTuple_construct1( i));
    }
    checkEdges(chosenEdges, nodes, 1, 0);
    //Check that the score is correct
    double totalScore2 = calculateZScoreOfReference(reference, nodeNumber, zMatrix);
    CuAssertDblEquals(testCase, totalScore2, totalScore, 0.000001);
    //Check that the stubs are properly connected.
    stList *allEdges = stList_copy(chosenEdges, NULL);
    stList_appendAll(allEdges, stubs);
    stList_appendAll(allEdges, chains);
    stList *components = getComponents(allEdges);
    CuAssertIntEquals(testCase, stList_length(stubs), stList_length(reference));
    CuAssertIntEquals(testCase, stList_length(stubs), stList_length(components));
    //Cleanup
    stList_destruct(components);
    stSortedSet_destruct(nodes);
    stList_destruct(allEdges);
    stList_destruct(chosenEdges);
}
Exemplo n.º 3
0
void Mover::update() {
    velocity += acceleration;
    velocity.limit(topspeed);
    location += velocity;
    checkEdges();
    
    acceleration *= 0; //reset, so that forces are applied fresh each frame
}
Exemplo n.º 4
0
      void exe()
   {
      for( auto * const submap : sub_maps )
      {
         auto &container( all_kernels.acquire() );
         auto &subcontainer( submap->all_kernels.acquire() );  
         container.insert( subcontainer.begin(),
                           subcontainer.end()   );
         all_kernels.release();
         submap->all_kernels.release();
      }
      /** check types, ensure all are linked **/
      checkEdges( source_kernels );
      /** adds in split/join kernels **/
      //enableDuplication( source_kernels, all_kernels );
      volatile bool exit_alloc( false );
      allocator alloc( (*this), exit_alloc );
      /** launch allocator in a thread **/
      std::thread mem_thread( [&](){
         alloc.run();
      });
     
      alloc.waitTillReady();

      scheduler sched( (*this) );
      sched.init();
      
      /** launch scheduler in thread **/
      std::thread sched_thread( [&](){
         sched.start();
      });

      volatile bool exit_para( false );
      /** launch parallelism monitor **/
      parallelism_monitor pm( (*this)     /** ref to this    **/, 
                              alloc       /** allocator      **/,
                              sched       /** scheduler      **/,
                              exit_para   /** exit parameter **/);
      std::thread parallel_mon( [&](){
         pm.start();
      });
      /** join scheduler first **/
      sched_thread.join();

      /** scheduler done, cleanup alloc **/
      exit_alloc = true;
      mem_thread.join();
      /** no more need to duplicate kernels **/
      exit_para = true;
      parallel_mon.join();

      /** all fifo's deallocated when alloc goes out of scope **/
      return; 
   }
void checkInputs(stSortedSet *nodes, stList *adjacencyEdges,
        stList *stubEdges, stList *chainEdges) {
    /*
     * Checks the inputs to the algorithm are as expected.
     */
    int64_t nodeNumber = stSortedSet_size(nodes);
    assert(nodeNumber % 2 == 0);
    if (nodeNumber > 0) {
        assert(stList_length(stubEdges) > 0);
    }
    assert(
            stList_length(stubEdges) + stList_length(chainEdges) == (nodeNumber
                    / 2));
    checkEdges(stubEdges, nodes, 0, 0);
    checkEdges(chainEdges, nodes, 0, 0);
    stList *stubsAndChainEdges = stList_copy(stubEdges, NULL);
    stList_appendAll(stubsAndChainEdges, chainEdges);
    checkEdges(stubsAndChainEdges, nodes, 1, 0);
    stList_destruct(stubsAndChainEdges);
    checkEdges(adjacencyEdges, nodes, 1, 1);
}
Exemplo n.º 6
0
void main()
{
	int i;
	int a = 0;
	int b=0;
	int w=0;
	int N, M;
	int S=0;
	int F=0;
	int k;
	int **edges;
	int *lenMin;  //lenMin[i] - длина кратчайшего пути от вершины s в i
	int *h;  //h[i] - вершина, предшествующая i-й вершине на кратчайшем пути
	N=checkAmount();
	if (N == EOF)
		return;
	if (checkInVertex(N,&S,&F) == EOF)
		return;
	M = checkLines(N);
	if (M == EOF)
		return;
	S = S - 1;
	F = F - 1;
	edges = (int**)malloc(N*sizeof(int*));
	for (i = 0; i < N; i++)
	{
		edges[i] = (int*)malloc(N*sizeof(int));
	}
	nullEgdes(N, edges);
	lenMin = (int*)malloc(N*sizeof(int));
	h = (int*)malloc(N*sizeof(int));
	for (i = 0; i < M; i++)
	{
		if (checkEdges(N, &a, &b, &w) == EOF)
			return;
		edges[a - 1][b - 1] = w;
		edges[b - 1][a - 1] = w;
	}
	for (i = 0; i < N; i++)
	{
		lenMin[i] = Infinity; //Сначала все кратчайшие пути из s в i равны бесконечности        
	}
	k = 0;	//счетчик кратчайших путей равен нулю
	Deykstra(N, &k, edges, &lenMin, &h, S, F);
	printOutput(N, S, F, k, h, lenMin);
	getchar();
	getchar();
}
stList *getPerfectMatching(stSortedSet *nodes,
        stList *adjacencyEdges,
        stList *(*matchingAlgorithm)(stList *edges, int64_t nodeNumber)) {

    checkEdges(adjacencyEdges, nodes, 1, 1); //Checks edges are clique

    if (stSortedSet_size(nodes) == 0) { //Some of the following functions assume there are at least 2 nodes.
        return stList_construct();
    }

    stList *nonZeroWeightAdjacencyEdges = getEdgesWithGreaterThanZeroWeight(
                adjacencyEdges);
    stList *chosenEdges = getSparseMatching(nodes, nonZeroWeightAdjacencyEdges, matchingAlgorithm);
    stList_destruct(nonZeroWeightAdjacencyEdges);
    makeMatchingPerfect(chosenEdges, adjacencyEdges, nodes);

    st_logDebug(
                "Chosen a perfect matching with %" PRIi64 " edges, %" PRIi64 " cardinality and %" PRIi64 " weight\n",
                stList_length(chosenEdges), matchingCardinality(chosenEdges),
                matchingWeight(chosenEdges));

    return chosenEdges;
}