Ejemplo n.º 1
0
void justine::robocar::AntCar::nextSmarterEdge(void)
{
    osmium::unsigned_object_id_type next_m_from = traffic.alist(m_from, m_to);
    size_t nes = traffic.nedges(next_m_from);
    if (!nes)
        return;

    osmium::unsigned_object_id_type next_m_to;

    if (traffic.get_type() == TrafficType::ANT) {
        next_m_to = ant();
    } else if (traffic.get_type() == TrafficType::ANT_RND) {
        next_m_to = ant_rnd();
    } else if (traffic.get_type() == TrafficType::ANT_RERND) {
        next_m_to = ant_rernd();
    } else {
        next_m_to = ant_mrernd();
    }


    if (traffic.alist(next_m_from, next_m_to) == m_from)
        next_m_to = (next_m_to + 1) % nes;

    if (traffic.palist(next_m_from, next_m_to) >
            traffic.salist(next_m_from, next_m_to)) {

        traffic.set_salist(m_from, m_to, traffic.salist(m_from, m_to) - 1);

        m_from = next_m_from;
        m_to = next_m_to;
        m_step = 0;

        traffic.set_salist(m_from, m_to, traffic.salist(m_from, m_to) + 1);
    }
}
int inserir(Fila *f, void *info, float (*compara_info)(void*,void*)) 
{
    if(fila_cheia(*f))
        return ERRO_FILA_CHEIA;
    int atual = f->fim;
    int anterior = ant(atual, f->capacidade);
    int cont = 0;
    while (cont < f->num_ele && compara_info(f->dados[anterior],info)) 
    {
        f->dados[atual] = f->dados[anterior];
        atual = anterior;
        anterior = ant(atual, f->capacidade);
        cont++;
    }
    f->dados[atual] = malloc (f->tamInfo);
    memcpy(f->dados[atual], info, f->tamInfo);
    f->fim++;
    f->num_ele++;
    if (f->fim == f->capacidade)
        f->fim = 0;
    return 0;
}
Ejemplo n.º 3
0
double compute_average_pheromone_update(OptimizationProblem &op) {
  SimpleAnt ant(op.get_max_tour_size());
  PheromoneMatrix matrix(op.number_of_vertices(), 0.0, 1.0);
  ant.construct_rational_solution(op, matrix, 0, 1);
  std::vector<unsigned int> tour = ant.get_vertices();
  double tour_length = op.eval_tour(tour);
  double pheromone_sum = 0.0;
  for(unsigned int i=0;i<tour.size();i++) {
    pheromone_sum += op.pheromone_update(tour[i], tour_length);
  }
  double pheromone_avg = pheromone_sum / tour.size();
  return pheromone_avg;
}
Ejemplo n.º 4
0
TEST(ChangeNameTransactionTest, PayrollTest) {

	int empid = 8;
	AddHourlyEmployee ahe(empid, "Test8", "Home8", 50.00);
	ahe.Execute();

	ChangeNameTransaction ant(empid, "Test88");
	ant.Execute();

	Employee *e = ((DatabaseProxy *)getInstance())->GetEmployee(empid);
	EXPECT_TRUE(e != 0);
	EXPECT_TRUE(e->GetName() == "Test88");
}
Ejemplo n.º 5
0
void speedtest(short test)
{
	unsigned BACKGROUND;
	if(test == 0) BACKGROUND=0xB00000;
	if(test == 1) BACKGROUND=0xFFFFFF;
	short start = 240;
	short cpuspeed = start;
	unsigned char cad[256];
	FILE *speed;
	
	do
	{	
		speed = fopen("/mnt/sd/speed.txt", "w");
		ClearScreen(BACKGROUND);
		if(test == 0) v_putcad(1,1,0x00ff00,BACKGROUND,"Prim-Speedtest");
		if(test == 1) v_putcad(1,1,0x006600,BACKGROUND,"Ant-Speedtest");
		v_putcad(1,6,0xffffff,BACKGROUND,"Testing Speed");
		if(cpuspeed > start) 
		{
			sprintf(cad,"%uMhz checked",cpuspeed-5);
			v_putcad(1,9,0xffffff,BACKGROUND,cad);
		}
		gp2x_video_flip();
		ClearScreen(BACKGROUND);
		if(test == 0) v_putcad(1,1,0x00ff00,BACKGROUND,"Prim-Speedtest");
		if(test == 1) v_putcad(1,1,0x006600,BACKGROUND,"Ant-Speedtest");
		v_putcad(1,6,0xffffff,BACKGROUND,"Testing Speed");
		if(cpuspeed > start) 
		{
			sprintf(cad,"%uMhz checked",cpuspeed-5);
			if(test == 0) v_putcad(1,9,0xffffff,BACKGROUND,cad);
			if(test == 1) v_putcad(1,9,0x000000,BACKGROUND,cad);
		}
		gp2x_video_flip();
		fprintf (speed,"set CPU-Frequency = %uMHz\r\n",cpuspeed);
		set_FCLK(cpuspeed);
		
		if(test == 0) prim();
		if(test == 1) ant();
		
		fprintf(speed,"%uMhz checked\n\n", cpuspeed);
		cpuspeed = cpuspeed + 5;
		fclose(speed);
		execl("sync",NULL);
	}
	while(1);	
}
Ejemplo n.º 6
0
void AntManager::Run(TileMap currentMap, TileMap& newMap)
{
	sf::Vector2i nestPos;
	
	newMap.Evaporation(m_evaporation);
	
	if (!currentMap.GetNestPosition(nestPos))
	{
		return;
	}
		
	for (auto i = 0u; i < m_antCount; ++i)
	{
		AntAgent ant(m_alpha, m_beta);		
		if (ant.FindFeed(currentMap, nestPos))
		{
			ant.MarkPath(newMap);
		}
	}
}
Ejemplo n.º 7
0
void CellAutomataAgent::evaluate(PPtr<KGridBasic> readLayer,
    PPtr<KGridBasic> writeLayer, int phase)
{
  switch (_problem) {
    case LIFE:
      gameOfLife(readLayer, writeLayer, phase);
      break;
      
    case BRAIN:
      brianBrain(readLayer, writeLayer, phase);
      break;
      
    case ANT:
      ant(readLayer, writeLayer, phase);
      break;
      
    default:
      break;
  }
}
Ejemplo n.º 8
0
Archivo: main.cpp Proyecto: CCJY/coliru
int main()
{
    ant() = ant();
    ent() = ent();
    int() = int();
}
Ejemplo n.º 9
0
void AntProjectPart::slotTargetMenuActivated(int id)
{
  ant(m_antOptions.m_targets[id]);
}
Ejemplo n.º 10
0
void AntProjectPart::slotBuild()
{
  ant(m_antOptions.m_defaultTarget);
}
Ejemplo n.º 11
0
retStateT Solver::resolveConflict() {
	recordLastUIPCauses();

	if (statistics_.num_clauses_learned_ - last_ccl_deletion_time_
			> statistics_.clause_deletion_interval()) {
		deleteConflictClauses();
		last_ccl_deletion_time_ = statistics_.num_clauses_learned_;
	}

	if (statistics_.num_clauses_learned_ - last_ccl_cleanup_time_ > 100000) {
		compactConflictLiteralPool();
		last_ccl_cleanup_time_ = statistics_.num_clauses_learned_;
	}

	statistics_.num_conflicts_++;

	assert(
			stack_.top().remaining_components_ofs() <= component_analyzer_.component_stack_size());

	assert(uip_clauses_.size() == 1);

	// DEBUG
	if (uip_clauses_.back().size() == 0)
		cout << " EMPTY CLAUSE FOUND" << endl;
	// END DEBUG

	stack_.top().mark_branch_unsat();
	//BEGIN Backtracking
	// maybe the other branch had some solutions
	if (stack_.top().isSecondBranch()) {
		return BACKTRACK;
	}

	Antecedent ant(NOT_A_CLAUSE);
	// this has to be checked since using implicit BCP
	// and checking literals there not exhaustively
	// we cannot guarantee that uip_clauses_.back().front() == TOS_decLit().neg()
	// this is because we might have checked a literal
	// during implict BCP which has been a failed literal
	// due only to assignments made at lower decision levels
	if (uip_clauses_.back().front() == TOS_decLit().neg()) {
		assert(TOS_decLit().neg() == uip_clauses_.back()[0]);
		var(TOS_decLit().neg()).ante = addUIPConflictClause(
				uip_clauses_.back());
		ant = var(TOS_decLit()).ante;
	}
//	// RRR
//	else if(var(uip_clauses_.back().front()).decision_level
//			< stack_.get_decision_level()
//			&& assertion_level_ <  stack_.get_decision_level()){
//         stack_.top().set_both_branches_unsat();
//         return BACKTRACK;
//	}
//
//
//	// RRR
	assert(stack_.get_decision_level() > 0);
	assert(stack_.top().branch_found_unsat());

	// we do not have to remove pollutions here,
	// since conflicts only arise directly before
	// remaining components are stored
	// hence
	assert(
			stack_.top().remaining_components_ofs() == component_analyzer_.component_stack_size());

	stack_.top().changeBranch();
	LiteralID lit = TOS_decLit();
	reactivateTOS();
	setLiteralIfFree(lit.neg(), ant);
//END Backtracking
	return RESOLVED;
}
Ejemplo n.º 12
0
void ant(unsigned char * pixels,int posX, int posY,float dir, int width, int height, int depth, senseMaker * senses[])
{
    
    
	if(depth> 0 && posX < width -10 && posY<height -10 && posX > 10 && posY > 10)
	{
		for(int i =0; i < ofRandom(200,600); i ++)
		{
			int value1 =  pixels[(posY*width + posX)*3]+ 
            pixels[(posY*width + posX)*3+1] + 
            pixels[(posY*width + posX)*3+2] ;
			
			int pixelPos = (posY*width+posX)*3;
			
			pixels[pixelPos ] = 255;
			pixels[pixelPos+1] = 255;
			pixels[pixelPos+2] = 255;
			
			
			int smallestDiff = 100000;
			int tHor = round(cos(dir) * 1.0f);
			int tVer = round(sin(dir) * 1.0f);
			float tDir = dir;
            
			int tmpValue= 0;
            
            for(float b = -PI/2.0f; b < PI/2.0f;b = b + PI/4.0f)
            {
                
                int ver = round(cos(b+dir) * 1.0f);
                int hor =  round(sin(b+dir) * 1.0f);
				
                
                tmpValue = 
                pixels[((posY+ver)*width + posX+hor)*3 ]+
                pixels[((posY+ver)*width + posX+hor)*3+1]+
                pixels[((posY+ver)*width + posX+hor)*3+2];
                if(abs(value1 - tmpValue) < smallestDiff && tmpValue < 255*3 )
                {
                    smallestDiff = abs(value1 - tmpValue);
                    tHor = hor;
                    tVer = ver;
                    tDir = b;
                }
                
            }
            
			
            
			if(depth> 0 && posX < width -10 && posY<height -10 && posX > 10 && posY > 10)
			{
				dir = dir*0.4 + tDir*0.6;
				posY = posY + tVer;
				posX = posX + tHor;
				
				if(ofRandom(0,100)<1)
				{
					ant(pixels,posX, posY,dir+ofRandom(0,PI*2),width, height,  depth-1,senses);
				}
				
			}
			else
			{
				break;
			}
            
		}
		
	}
}