Exemplo n.º 1
0
void
MonthDayRuleTest::test_lifecycle_valid()
{
	const String ruleName("MyRule");
	const Month refMonth(12);
	const DayOfMonth refDayOfMonth(31);

	//test: MontDayRule::MonthDayRule();
	MonthDayRule rule1;
	rule1.setRuleName(ruleName);
	CPPUNIT_ASSERT(1 == rule1.getMonth().getValue());
	CPPUNIT_ASSERT(1 == rule1.getDayOfMonth().getValue());
	


	//test: MontDayRule::MonthDayRule(const MonthDayRule& other);
	MonthDayRule rule2 (rule1);
	CPPUNIT_ASSERT(1 == rule2.getMonth().getValue());
	CPPUNIT_ASSERT(1 == rule2.getDayOfMonth().getValue());
	CPPUNIT_ASSERT(ruleName == rule2.getRuleName());
	

	//test: MontDayRule::MonthDayRule(const String& ruleName, const Month& month, const DayOfMonth& dayOfMonth);
	MonthDayRule rule3 ("Rule3", refMonth, refDayOfMonth);
	CPPUNIT_ASSERT(refMonth == rule3.getMonth());
	CPPUNIT_ASSERT(refDayOfMonth == rule3.getDayOfMonth());
	

	//test: MontDayRule::MonthDayRule(const String& ruleName, MonthOfYear::eMonthOfYear month, const DayOfMonth& dayOfMonth);
	MonthDayRule rule4("Rule4", MonthOfYear::December, refDayOfMonth);
	CPPUNIT_ASSERT(refMonth == rule3.getMonth());
	CPPUNIT_ASSERT(refDayOfMonth == rule3.getDayOfMonth());
	
}
Exemplo n.º 2
0
void AIElementGroupSwarm::step(Real evt)
{
    //LogManager::getSingleton().logMessage("Swarm step.");
    int i;
    Vector3 v1,v2,v3,mVel;
    for (i=0; i!=nodes.size(); i++)
    {
        AIElement* n = nodes[i];
        v1=rule1(n);
        v2=rule2(n);
        v3=rule3(n);
        mVel=n->getVelocity();
        mVel+=v1+v2+v3;
        //LogManager::getSingleton().logMessage(StringConverter::toString(nodes.size()));
        //	LogManager::getSingleton().logMessage(StringConverter::toString(v2));
        //	LogManager::getSingleton().logMessage(StringConverter::toString(v3));
        //boundPosition(nodes[i]);
        //tend_to_pos(nodes[i]);
        //n->setPosition(n->getPosition()+mVel/(100000)*evt);
        n->setVelocity(mVel*0.0001);
        tendToPos(getPos());
        n->sendCommand1(StringConverter::toString(GOTO_NPC));
        n->sendCommand2(StringConverter::toString(n->getPosition()));
    }
}
Exemplo n.º 3
0
  virtual void SetUp() {
 		fuzzy = new Fuzzy(1);
    	//Fuzzy Sets -  Input 0 - Velocidade
	  	FuzzySet* velocidadeBaixa = new FuzzySet(0.0, 0.0, 30, 60);
	  	FuzzySet* velocidadeMedia = new FuzzySet(30, 60, 60, 90);
	  	FuzzySet* velocidadeAlta = new FuzzySet(60, 90, 100, 100);

	  	//Index 0 - Input - Velocidade
	  	fuzzy->addFuzzySet(0, 0, velocidadeBaixa);   //Set 0
	  	fuzzy->addFuzzySet(0, 1, velocidadeMedia);   //Set 1
	  	fuzzy->addFuzzySet(0, 2, velocidadeAlta);   //Set 2

	  	//Fuzzy Sets - Output - Consumo
	  	FuzzySet* consumoAlto = new FuzzySet(0.0, 0.0, 3, 6);
	  	FuzzySet* consumoMedio = new FuzzySet(3, 6, 6, 9);
	  	FuzzySet* consumoBaixo = new FuzzySet(6, 9, 10, 10);


	  	//Index 2 - Output
	  	fuzzy->addFuzzySet(2, 0,consumoAlto);
	  	fuzzy->addFuzzySet(2, 1, consumoMedio);
	  	fuzzy->addFuzzySet(2, 2, consumoBaixo);

	  	//Rules Base
		FuzzyRule rule1(velocidadeMedia, consumoBaixo);
	  	FuzzyRule rule2(velocidadeBaixa, consumoMedio);
	  	FuzzyRule rule3(velocidadeAlta, consumoAlto);


	  	fuzzy->addRule(rule1);
	 	fuzzy->addRule(rule2);
	  	fuzzy->addRule(rule3);
  }
Exemplo n.º 4
0
void Flock::update(const Scene & scene){
	for(std::vector<Boid * >::iterator it = boids.begin(); it != boids.end(); ++it) {
		 	int index = it - boids.begin();
		 	Vector v = rule1(index) + rule2(index) + rule3(index);
		 	v = v * damping;
			Boid * boid = *it;
		 	v = v + boid->getVelocity();

		 	if(v.getLength() > maxSpeed){
		 		v = v * (maxSpeed/v.getLength());
		 	}

			Point p = boid->getCenter();
			double wind = 0.12;
			Vector windVector;
			if(p.x> 900 ){
				windVector = Vector(-wind,0);
			} else if(p.x< 150 ){
				windVector = Vector(wind,0);
			} else if(p.y> 350 ){
				windVector = Vector(0,-wind);
			} else if(p.y< 150 ){
				windVector = Vector(0,wind);
			}

			boid->setVelocity(v + windVector);
		 	boid->setCenter(boid->getCenter() + boid->getVelocity());
	}
}
Exemplo n.º 5
0
void BoidFlock::update() {
	for (unsigned i = 0; i < boidCount; i++) {
		Boid *b = boids[i];
		vec3 v1 = rule1(b);
		vec3 v2 = rule2(b);
		vec3 v3 = rule3(b);
		vec3 pos = boundPosition(b);

		b->incVelocity((v1 + v2 + v3 + pos) / 100.0f);
		limitSpeed(b);
		b->update();
	}
}
Exemplo n.º 6
0
bool funcCHAR(ParserParam &param, Token *tok){
	switch(param.stack.back()){
		case 0:
			shift(param,tok,36);
			break;
		case 3:
			shift(param,tok,36);
			break;
		case 7:
			if(!rule3(param)) return false;
			break;
		case 8:
			if(!rule4(param)) return false;
			break;
		case 9:
			shift(param,tok,36);
			break;
		case 12:
			if(!rule5(param)) return false;
			break;
		case 14:
			if(!rule6(param)) return false;
			break;
		case 19:
			shift(param,tok,36);
			break;
		case 25:
			if(!rule15(param)) return false;
			break;
		case 27:
			shift(param,tok,36);
			break;
		case 30:
			if(!rule17(param)) return false;
			break;
		case 31:
			if(!rule18(param)) return false;
			break;
		case 33:
			if(!rule19(param)) return false;
			break;
		case 34:
			if(!rule20(param)) return false;
			break;
		default:
			return false;
		break;
	}
	return true;
}
Exemplo n.º 7
0
bool funcEND(ParserParam &param, Token *tok){
	switch(param.stack.back()){
		case 1:
			shift(param,tok,2);
			break;
		case 2:
			param.isAccept = true;
			break;
		case 3:
			if(!rule2(param)) return false;
			break;
		case 4:
			if(!rule1(param)) return false;
			break;
		case 7:
			if(!rule3(param)) return false;
			break;
		case 8:
			if(!rule4(param)) return false;
			break;
		case 12:
			if(!rule5(param)) return false;
			break;
		case 14:
			if(!rule6(param)) return false;
			break;
		case 25:
			if(!rule15(param)) return false;
			break;
		case 30:
			if(!rule17(param)) return false;
			break;
		case 31:
			if(!rule18(param)) return false;
			break;
		case 33:
			if(!rule19(param)) return false;
			break;
		case 34:
			if(!rule20(param)) return false;
			break;
		default:
			return false;
		break;
	}
	return true;
}
Exemplo n.º 8
0
void
MonthWeekDayRuleTest::test_lifecycle_valid()
{
	const String ruleName("MyRule");
	const MonthOfYear::eMonthOfYear refMonth = MonthOfYear::January;
	const MonthWeek::eMonthWeek refWeekOfMonth = MonthWeek::First ;
	const WeekDay::eWeekDay refWeekDay = WeekDay::Sunday;

	//test: MontDayRule::MonthDayRule();
	MonthWeekDayRule rule1;
	rule1.setRuleName(ruleName);
	CPPUNIT_ASSERT(refMonth == rule1.getMonth().monthOfYear()); 
	CPPUNIT_ASSERT(refWeekOfMonth == rule1.getMonthWeek());
	CPPUNIT_ASSERT(refWeekDay == rule1.getWeekDay()); 


	//test: MontDayRule::MonthDayRule(const MonthDayRule& other);
	MonthWeekDayRule rule2 (rule1);
	CPPUNIT_ASSERT(refMonth == rule2.getMonth().monthOfYear()); 
	CPPUNIT_ASSERT(refWeekOfMonth == rule2.getMonthWeek());
	CPPUNIT_ASSERT(refWeekDay == rule2.getWeekDay());
	CPPUNIT_ASSERT(ruleName == rule2.getRuleName());

	//test: MonthWeekDayRule::MonthWeekDayRule(const String& ruleName, const Month& month, MonthWeek::eMonthWeek weekInMonth, WeekDay::eWeekDay dayOfWeek);

	MonthWeekDayRule rule3 ("Rule3", Month(1), refWeekOfMonth, refWeekDay);
	CPPUNIT_ASSERT(refMonth == rule3.getMonth().monthOfYear());
	CPPUNIT_ASSERT(refWeekOfMonth == rule3.getMonthWeek());
	CPPUNIT_ASSERT(refWeekDay == rule3.getWeekDay());

	//test: MonthWeekDayRule::MonthWeekDayRule(const String& ruleName, MonthOfYear::eMonthOfYear month, WeekOfMonth::eWeekOfMonth weekInMonth, WeekDay::eWeekDay dayOfWeek);
	MonthWeekDayRule rule4("Rule4", refMonth, refWeekOfMonth, refWeekDay);
	CPPUNIT_ASSERT(refMonth == rule4.getMonth().monthOfYear());
	CPPUNIT_ASSERT(refWeekOfMonth == rule4.getMonthWeek());
	CPPUNIT_ASSERT(refWeekDay == rule4.getWeekDay());
}
Exemplo n.º 9
0
char		pose(t_board *board, t_pos *move, char current, char rules)
{
    int		i;
    char		get;
    int		iget;


    /* printf("At %i-%i: ", cor.move->x, cor.move->y); */

    // Pose
    get = get_board(board, move->x, move->y);
    if ((get == EMPTY) &&
            (!(rules & RULE3) || (rule3(board, move->x, move->y, current))))
    {
        set_board(board, move->x, move->y, current);
        printf("Placed a ");
        if (current == BLACK)
        {
            printf("Black");
            current = WHITE;
        }
        else
        {
            printf("White");
            current = BLACK;
        }
        printf(" Stone at %i:%i\n", move->x, move->y);

        // Prise
        iget = getprise(board, move->x, move->y, current);
        if (iget)
        {
            printf("Taken %i ", iget*2);
            if (current == BLACK)
            {
                board->blacks += iget;
                printf("Black Stones (%i total)\n", board->blacks*2);
            }
            else
            {
                board->whites += iget;
                printf("Whites Stones (%i total)\n", board->whites*2);
            }
            prise(board, move->x, move->y, current);
        }

        // Règle de 5
        // (rules & RULE5) &&
        for (i = 0; i < 19*19; i++)
        {
            move->x = i / 19;
            move->y = i % 19; //
            if ((get_board(board, move->x, move->y) == OPPOSITE(current)) && (rule5(board, move->x, move->y, OPPOSITE(current), rules)))
            {
                if (current == WHITE)
                    printf("Blacks wins with a row!\n");
                if (current == BLACK)
                    printf("Whites wins with a row!\n");
                return (OPPOSITE(current) + 10);
            }
        }

    }
    else
    {
        printf("There's ");
        switch (get)
        {
        case BLACK:
            printf("a Black Stone");
            break;
        case WHITE:
            printf("a White Stone");
            break;
        case EMPTY:
            printf("nothing");
            break;
        }
        printf(" at %i:%i\n", move->x, move->y);
    }


    return (current);
}
Exemplo n.º 10
0
char		game_loop(t_board *board, t_surfaces *surf, char mode)
{
    t_pos		moveIA;
    t_pos		moveHint;
    t_pos		move;
    char		rules;
    char		hint;

    SDL_Rect	pos; // Pour les placements dans la fenêtre
    SDL_Rect	cor; // Pour les placements dans le board

    SDL_Event     event;
    char		current;

    current = BLACK;
    SDL_ShowCursor(0);
    init_board(board);
    rules = RULE3 | RULE5;

    cor.x = 0;
    cor.y = 0;
    hint = 0;

    SDL_WaitEvent(&event);
    printf("New Game\n");
    while (current)
    {
        // Fuite
        if (((event.type == SDL_KEYDOWN) && (event.key.keysym.sym == SDLK_ESCAPE)) ||
                (event.type == SDL_QUIT))
            current = 0;

        // Background
        show_background(surf->background, surf->screen);

        // Click
        if (event.type == SDL_MOUSEBUTTONUP)
        {
            // Mouvements sur le board: position du curseur
            if ((cor.x >= 0) && (cor.x < 19) && (cor.y >= 0) && (cor.y < 19))
            {
                move.x = cor.x;
                move.y = cor.y;
                current = pose(board, &move, current, rules);

                // IA
                if (mode && (current == WHITE))
                {
                    callIA(board, rules, &moveIA, current);
                    current = pose(board, &moveIA, current, rules);
                }

                if (hint)
                    hint = 2;
            }
            // Mouvements en bas du board: sélection des règles
            else if (event.motion.y > 632)
            {
                if (event.motion.x < 160)
                    rules = rules ^ RULE3;
                else if (event.motion.x < 320)
                    rules = rules ^ RULE5;
                else if (event.motion.x < 480)
                {
                    hint = !hint;
                    if (hint)
                        hint++;
                }
                else if (event.motion.x < 640)
                    return (42);
            }

            // Calcul du hint
            if ((hint > 1) && (current < 3))
            {
                callIA(board, rules, &moveHint, current);
                /* printf("Hint at %i:%i\n", moveHint.x, moveHint.y); */
                hint--;
            }
        }

        // Affichage de l'état des règles
        pos.w = 320;
        pos.h = 56;
        pos.y = 630;

        if (rules & RULE3)
        {
            pos.x = 1;
            SDL_BlitSurface(surf->rule3, NULL, surf->screen, &pos);
        }
        if (rules & RULE5)
        {
            pos.x = 161;
            SDL_BlitSurface(surf->rule5, NULL, surf->screen, &pos);
        }
        if (hint)
        {
            pos.x = 320;
            SDL_BlitSurface(surf->hint, NULL, surf->screen, &pos);
        }


        // Affichage du Hint
        if (hint)
        {
            pos.x = moveHint.x * 32 +16;
            pos.y = moveHint.y * 32 +16;
            pos.w = 32;
            pos.h = 32;
            SDL_BlitSurface(surf->cursor, NULL, surf->screen, &pos);
        }

        // Affichage des pions
        place_pawns(board, surf);

        // Move
        if ((event.type == SDL_MOUSEMOTION) || (event.type == SDL_MOUSEBUTTONUP))
        {
            pos.w = 32;
            pos.h = 32;
            pos.x = (event.motion.x / 32) * 32 - 16;
            pos.y = (event.motion.y / 32) * 32 - 16;
            cor.x = event.motion.x / 32 - 1;
            cor.y = event.motion.y / 32 - 1;
            /* printf("x:%i y:%i\n", pos.x / 32, pos.y / 32); */

            if ((cor.x >= 0) && (cor.x < 19) && (cor.y >= 0) && (cor.y < 19))
            {
                if (get_board(board, cor.x, cor.y) == EMPTY)
                {

                    if (!getprise(board, cor.x, cor.y, current) && (rules & RULE3)
                            && (!rule3(board, cor.x, cor.y, current)))
                        SDL_BlitSurface(surf->nopestone, NULL, surf->screen, &pos);
                    else if (current == BLACK)
                    {
                        SDL_BlitSurface(surf->blackstone, NULL, surf->screen, &pos);
                        SDL_BlitSurface(surf->cursor, NULL, surf->screen, &pos);
                    }
                    else
                    {
                        SDL_BlitSurface(surf->whitestone, NULL, surf->screen, &pos);
                        SDL_BlitSurface(surf->cursor, NULL, surf->screen, &pos);
                    }
                }
                else
                    SDL_BlitSurface(surf->nopestone, NULL, surf->screen, &pos);
                SDL_ShowCursor(0);
            }
            else if (event.motion.y > 632)
                SDL_ShowCursor(1);
        }

        SDL_Flip(surf->screen);

        // Victoire par capture
        if (board->whites >= 5)
        {
            printf("Blacks wins with captures!\n");
            current = BLACK + 10;
        }
        if (board->blacks >= 5)
        {
            printf("Whites wins with captures!\n");
            current = WHITE + 10;
        }

        // Quit de victoire
        while (current > 10)
        {
            SDL_ShowCursor(1);
            show_background(surf->exit, surf->screen);
            place_pawns(board, surf);
            SDL_Flip(surf->screen);
            SDL_WaitEvent(&event);
            if (event.type == SDL_MOUSEBUTTONUP)
                return (current - 10);
            if (((event.type == SDL_KEYDOWN) && (event.key.keysym.sym == SDLK_ESCAPE)) ||
                    (event.type == SDL_QUIT))
            {
                current -= 10;
                current = OPPOSITE(current);
                break;
            }
        }

        SDL_WaitEvent(&event);

    }
    return (42);
}
Exemplo n.º 11
0
int main()
{
	int i,j,k;
	int l,m,n,o,bc,flag=0,count1=0,x=0,count2=0,row=0,count3=0,col=0,col2=0,prevcount=0,count5=0,size1=2,size2=3;
	int cancount=0,lk,lm,count11=0;
	
	int arr1[3],arr2[3],arr3[3];
	int ab,div1,div2,count10=0,initial=0,initial2=0,candicount=0,prevcount1=0;
	
	
	for(i=1;i<=size;i++)
	{
		for(j=1;j<=size;j++)
		{
			headarray[i][j]=NULL;	
		}
	}
	scanf("%d",&size);
	memset(check, 0, (sizeof check[0][0])*size*size);
	memset(notin, 0, (sizeof notin[0][0])*size*size);
	memset(see, 0, (sizeof see[0][0])*size*size);
	// taking sudoku input
	
	for(i=1;i<=(size*size);i++)
	{
		for(j=1;j<=(size*size);j++)
		{
			scanf("%d",&arr[i][j]);
			if(arr[i][j]==0)
			count++;
		}

	}
	
	
	traverse();		            // updating missing no matrix
	cross();	   	    	// crosshatching
	candidatelist();		// preparing candidate list
	rule1();			// rule1
	while(1)
	{
		prevcount1=count;
				    
		rule1();		    	// rule1
		rule2_box();			//rule2 for box
		rule2_row();			// rule2 column
		rule2_col();			// rule 2 for row
		rule1();	    		// rule 1				
		rule3();			// rule 3
		rule2_box();			//rule2 for box
		rule2_row();			
		rule2_col();		    
		rule4();			// rule 4
		if(prevcount1==count)
		break;
				    
	
	}		    
	
	for(i=1;i<=size*size;i++)
	{

		for(j=1;j<=size*size;j++)
		{
			printf("%d ",arr[i][j]);

		}
		printf("\n");
	}
	
return 0;

}
Exemplo n.º 12
0
bool funcNUM(ParserParam &param, Token *tok){
	switch(param.stack.back()){
		case 3:
			if(!rule2(param)) return false;
			break;
		case 4:
			if(!rule1(param)) return false;
			break;
		case 7:
			if(!rule3(param)) return false;
			break;
		case 8:
			if(!rule4(param)) return false;
			break;
		case 12:
			if(!rule5(param)) return false;
			break;
		case 14:
			if(!rule6(param)) return false;
			break;
		case 19:
			if(!rule67(param)) return false;
			break;
		case 22:
			shift(param,tok,23);
			break;
		case 25:
			if(!rule15(param)) return false;
			break;
		case 27:
			shift(param,tok,99);
			break;
		case 28:
			shift(param,tok,99);
			break;
		case 30:
			if(!rule17(param)) return false;
			break;
		case 31:
			if(!rule18(param)) return false;
			break;
		case 33:
			if(!rule19(param)) return false;
			break;
		case 34:
			if(!rule20(param)) return false;
			break;
		case 37:
			shift(param,tok,99);
			break;
		case 39:
			if(!rule25(param)) return false;
			break;
		case 41:
			if(!rule26(param)) return false;
			break;
		case 42:
			shift(param,tok,99);
			break;
		case 44:
			if(!rule27(param)) return false;
			break;
		case 46:
			if(!rule28(param)) return false;
			break;
		case 48:
			shift(param,tok,99);
			break;
		case 50:
			shift(param,tok,99);
			break;
		case 52:
			shift(param,tok,99);
			break;
		case 53:
			if(!rule29(param)) return false;
			break;
		case 55:
			shift(param,tok,99);
			break;
		case 57:
			shift(param,tok,99);
			break;
		case 58:
			if(!rule30(param)) return false;
			break;
		case 59:
			if(!rule31(param)) return false;
			break;
		case 60:
			shift(param,tok,99);
			break;
		case 62:
			if(!rule32(param)) return false;
			break;
		case 63:
			shift(param,tok,99);
			break;
		case 65:
			if(!rule33(param)) return false;
			break;
		case 67:
			shift(param,tok,99);
			break;
		case 70:
			shift(param,tok,99);
			break;
		case 73:
			shift(param,tok,99);
			break;
		case 76:
			shift(param,tok,99);
			break;
		case 79:
			shift(param,tok,99);
			break;
		case 81:
			shift(param,tok,99);
			break;
		case 84:
			shift(param,tok,99);
			break;
		case 87:
			shift(param,tok,99);
			break;
		case 89:
			shift(param,tok,99);
			break;
		case 93:
			shift(param,tok,99);
			break;
		case 96:
			shift(param,tok,99);
			break;
		case 100:
			if(!rule54(param)) return false;
			break;
		case 101:
			if(!rule55(param)) return false;
			break;
		case 102:
			if(!rule56(param)) return false;
			break;
		case 103:
			if(!rule57(param)) return false;
			break;
		case 104:
			if(!rule58(param)) return false;
			break;
		case 105:
			if(!rule59(param)) return false;
			break;
		case 106:
			if(!rule60(param)) return false;
			break;
		case 107:
			if(!rule61(param)) return false;
			break;
		case 108:
			if(!rule62(param)) return false;
			break;
		case 109:
			if(!rule63(param)) return false;
			break;
		case 110:
			if(!rule64(param)) return false;
			break;
		case 111:
			if(!rule65(param)) return false;
			break;
		case 112:
			if(!rule66(param)) return false;
			break;
		default:
			return false;
		break;
	}
	return true;
}
Exemplo n.º 13
0
bool funcSEMI(ParserParam &param, Token *tok){
	switch(param.stack.back()){
		case 3:
			if(!rule2(param)) return false;
			break;
		case 4:
			if(!rule1(param)) return false;
			break;
		case 6:
			shift(param,tok,7);
			break;
		case 7:
			if(!rule3(param)) return false;
			break;
		case 8:
			if(!rule4(param)) return false;
			break;
		case 12:
			if(!rule5(param)) return false;
			break;
		case 14:
			if(!rule6(param)) return false;
			break;
		case 24:
			shift(param,tok,25);
			break;
		case 25:
			if(!rule15(param)) return false;
			break;
		case 27:
			shift(param,tok,39);
			break;
		case 28:
			shift(param,tok,39);
			break;
		case 30:
			if(!rule17(param)) return false;
			break;
		case 31:
			if(!rule18(param)) return false;
			break;
		case 33:
			if(!rule19(param)) return false;
			break;
		case 34:
			if(!rule20(param)) return false;
			break;
		case 37:
			shift(param,tok,39);
			break;
		case 39:
			if(!rule25(param)) return false;
			break;
		case 40:
			shift(param,tok,41);
			break;
		case 41:
			if(!rule26(param)) return false;
			break;
		case 43:
			shift(param,tok,44);
			break;
		case 44:
			if(!rule27(param)) return false;
			break;
		case 45:
			shift(param,tok,46);
			break;
		case 46:
			if(!rule28(param)) return false;
			break;
		case 50:
			shift(param,tok,39);
			break;
		case 52:
			shift(param,tok,39);
			break;
		case 53:
			if(!rule29(param)) return false;
			break;
		case 57:
			shift(param,tok,39);
			break;
		case 58:
			if(!rule30(param)) return false;
			break;
		case 59:
			if(!rule31(param)) return false;
			break;
		case 61:
			shift(param,tok,62);
			break;
		case 62:
			if(!rule32(param)) return false;
			break;
		case 64:
			shift(param,tok,65);
			break;
		case 65:
			if(!rule33(param)) return false;
			break;
		case 66:
			if(!rule35(param)) return false;
			break;
		case 68:
			if(!rule34(param)) return false;
			break;
		case 69:
			if(!rule37(param)) return false;
			break;
		case 71:
			if(!rule36(param)) return false;
			break;
		case 72:
			if(!rule39(param)) return false;
			break;
		case 74:
			if(!rule38(param)) return false;
			break;
		case 75:
			if(!rule41(param)) return false;
			break;
		case 77:
			if(!rule40(param)) return false;
			break;
		case 78:
			if(!rule44(param)) return false;
			break;
		case 80:
			if(!rule42(param)) return false;
			break;
		case 82:
			if(!rule43(param)) return false;
			break;
		case 83:
			if(!rule46(param)) return false;
			break;
		case 85:
			if(!rule45(param)) return false;
			break;
		case 86:
			if(!rule47(param)) return false;
			break;
		case 88:
			if(!rule48(param)) return false;
			break;
		case 91:
			if(!rule49(param)) return false;
			break;
		case 92:
			if(!rule50(param)) return false;
			break;
		case 95:
			if(!rule51(param)) return false;
			break;
		case 98:
			if(!rule52(param)) return false;
			break;
		case 99:
			if(!rule53(param)) return false;
			break;
		case 113:
			if(!rule68(param)) return false;
			break;
		default:
			return false;
		break;
	}
	return true;
}
Exemplo n.º 14
0
bool funcREAD(ParserParam &param, Token *tok){
	switch(param.stack.back()){
		case 3:
			if(!rule2(param)) return false;
			break;
		case 4:
			if(!rule1(param)) return false;
			break;
		case 7:
			if(!rule3(param)) return false;
			break;
		case 8:
			if(!rule4(param)) return false;
			break;
		case 12:
			if(!rule5(param)) return false;
			break;
		case 14:
			if(!rule6(param)) return false;
			break;
		case 25:
			if(!rule15(param)) return false;
			break;
		case 27:
			shift(param,tok,63);
			break;
		case 28:
			shift(param,tok,63);
			break;
		case 30:
			if(!rule17(param)) return false;
			break;
		case 31:
			if(!rule18(param)) return false;
			break;
		case 33:
			if(!rule19(param)) return false;
			break;
		case 34:
			if(!rule20(param)) return false;
			break;
		case 37:
			shift(param,tok,63);
			break;
		case 39:
			if(!rule25(param)) return false;
			break;
		case 41:
			if(!rule26(param)) return false;
			break;
		case 44:
			if(!rule27(param)) return false;
			break;
		case 46:
			if(!rule28(param)) return false;
			break;
		case 50:
			shift(param,tok,63);
			break;
		case 52:
			shift(param,tok,63);
			break;
		case 53:
			if(!rule29(param)) return false;
			break;
		case 57:
			shift(param,tok,63);
			break;
		case 58:
			if(!rule30(param)) return false;
			break;
		case 59:
			if(!rule31(param)) return false;
			break;
		case 62:
			if(!rule32(param)) return false;
			break;
		case 65:
			if(!rule33(param)) return false;
			break;
		default:
			return false;
		break;
	}
	return true;
}
Exemplo n.º 15
0
TEST_F(FuzzyTest, testarFuzzificationComDuasEntradas){

	Fuzzy* fuzzy2 = new Fuzzy(2);
	
    //Fuzzy Sets -  Input 0 - Velocidade
	FuzzySet* velocidadeBaixa = new FuzzySet(0.0, 0.0, 30, 60);
	FuzzySet* velocidadeMedia = new FuzzySet(30, 60, 60, 90);
	FuzzySet* velocidadeAlta = new FuzzySet(60, 90, 100, 100);

	//Index 0 - Input - Velocidade
	fuzzy2->addFuzzySet(0, 0, velocidadeBaixa);   //Set 0
	fuzzy2->addFuzzySet(0, 1, velocidadeMedia);   //Set 1
	fuzzy2->addFuzzySet(0, 2, velocidadeAlta);   //Set 2
	
	//Fuzzy Sets -  Input 1 - Distância
	FuzzySet* distanciaPequena = new FuzzySet(0.0, 0.0, 15, 30);
	FuzzySet* distanciaMedia = new FuzzySet(15, 30, 30, 45);
	FuzzySet* distanciaGrande = new FuzzySet(30, 45, 100, 100);

	//Index 1 - Input - Distância
	fuzzy2->addFuzzySet(1, 0, distanciaPequena);   //Set 0
	fuzzy2->addFuzzySet(1, 1, distanciaMedia);   //Set 1
	fuzzy2->addFuzzySet(1, 2, distanciaGrande);   //Set 2

	//Fuzzy Sets - Output - Consumo
	FuzzySet* frearPouco = new FuzzySet(0.0, 0.0, 3, 6);
	FuzzySet* frearMedio = new FuzzySet(3, 6, 6, 9);
	FuzzySet* frearMuito = new FuzzySet(6, 9, 10, 10);


	//Index 2 - Output
	fuzzy2->addFuzzySet(2, 0,frearPouco);
	fuzzy2->addFuzzySet(2, 1, frearMedio);
	fuzzy2->addFuzzySet(2, 2, frearMuito);
 	//Rules Base
	FuzzyRule rule1(velocidadeBaixa, distanciaPequena, frearMuito);
  	FuzzyRule rule2(velocidadeBaixa, distanciaMedia, frearMedio);
  	FuzzyRule rule3(velocidadeAlta, distanciaGrande, frearPouco);


  	fuzzy2->addRule(rule1);
 	fuzzy2->addRule(rule2);
  	fuzzy2->addRule(rule3);
  	
  	
  	/****************************/
  		
  	//Definindo o valor crisp da Velocidade
    fuzzy2->setInputs(0, 60);
    
    //Definindo o valor crisp da Distancia
    fuzzy2->setInputs(1, 30);

    //Fuzzificando
    fuzzy2->fuzzify(0);
    fuzzy2->fuzzify(1);

    EXPECT_FLOAT_EQ(0, fuzzy2->getFuzzification(1, 0));
    EXPECT_FLOAT_EQ(1, fuzzy2->getFuzzification(1, 1));
    EXPECT_FLOAT_EQ(0, fuzzy2->getFuzzification(1, 2));
	/********/
	    
 

	/****************************/
	
    fuzzy2->setInputs(1, 37);	
    fuzzy2->fuzzify(1);
    
    EXPECT_FLOAT_EQ(0, fuzzy2->getFuzzification(1, 0));
    EXPECT_FLOAT_EQ(0.5333333, fuzzy2->getFuzzification(1, 1));
    EXPECT_FLOAT_EQ(0.46666664, fuzzy2->getFuzzification(1, 2)); 
    /***************************/
    
    
    fuzzy2->setInputs(0, 50);
    fuzzy2->setInputs(1, 29);
	
	fuzzy2->fuzzify(0);
    fuzzy2->fuzzify(1);	    
    fuzzy2->evaluate();
    
    float freio = fuzzy2->desfuzzify();
    
    EXPECT_FLOAT_EQ(6.1111112, freio); 	
	
}