Ejemplo n.º 1
0
Archivo: PolyDDV.cpp Proyecto: 8l/rose
void PolyDDV::computeHull(PolyDDV& ddv)
{
  if (ddv.getSize() != _types.size())
    return;
  int i;
  for (i = 0; i < ddv.getSize(); ++i)
    {
      if (ddv.isPlus(i))
	{
	  if (isEq(i) || isScalar(i))
	    setPlus(i);
	  else if (isMinus(i))
	    setStar(i);
	}
      else if (ddv.isMinus(i))
	{
	  if (isEq(i) || isScalar(i))
	    setMinus(i);
	  else if (isPlus(i))
	    setStar(i);
	}
      else if (ddv.isStar(i))
	setStar(i);
      else if (ddv.isScalar(i) && ! isStar(i))
	{
	  int s1 = ddv.getScalar(i);
	  if (isScalar(i) || isEq(i))
	    {
	      int s2 = 0;
	      if (isScalar(i))
		s2 = getScalar(i);
	      if (s1 > 0 && s2 < 0 || s1 < 0 && s2 > 0)
		setStar(i);
	      else if (s1 > 0 && s1 != s2)
		setPlus(i);
	      else if (s1 < 0 && s1 != s2)
		setMinus(i);
	    }
	  else
	    {
	      if (s1 > 0 && isMinus(i) || s1 < 0 && isPlus(i))
		setStar(i);
	    }
	}
    }
}
// store the rational representation of exp into rat, according to the
// most recently generated model.
static bool ExpModelRational(const CVC3::Expr &exp, CVC3::Rational &rat)
{
  // usual case, the expression is already an integer. it would be nice if
  // this was the 'always' case (except with assignments for function symbols,
  // which shouldn't get here), but it is not.
  if (exp.isRational()) {
    rat = exp.getRational();
    return true;
  }

  if (isPlus(exp)) {
    if (!ExpModelRational(exp[0], rat))
      return false;
    for (int i = 1; i < exp.arity(); i++) {
      CVC3::Rational crat;
      if (!ExpModelRational(exp[i], crat))
        return false;
      rat += crat;
    }
    return true;
  }

  if (isMult(exp)) {
    if (!ExpModelRational(exp[0], rat))
      return false;
    for (int i = 1; i < exp.arity(); i++) {
      CVC3::Rational crat;
      if (!ExpModelRational(exp[i], crat))
        return false;
      rat *= crat;
    }
    return true;
  }

  // see if this is a key in the model we generated.
  for (long i = 0; i < model_size; i++) {
    if (model_vars[i] == ToExp(exp))
      return ExpModelRational(FromExp(model_vals[i]), rat);
  }

  // printf("ERROR: Unknown expression from model: %s\n",
  //        exp.toString().c_str());

  return false;
}
Ejemplo n.º 3
0
/* <e2> [ + <e3> ] */
static Expression *e3(void) {
  Expression *left = e2();
  enum EKind kind;

  if (isPlus()) {
    kind = ePLUS;
  } else {
    return left;
  }

  consume();

  Expression *e = NEW(Expression);

  e->kind = kind;

  e->left = left;
  e->right = e3();

  return e;
}
Ejemplo n.º 4
0
            bool Number::IsValid(char character) {

                switch ((States) _currentState) {
                    case States::Start:
                        return isMinus(character) || isDigit(character);
                    case States::Negation:
                        return isDigit(character);
                    case States::RationalPercent:
                        return isDot(character) || isExponentialSymbol(character);
                    case States::Number:
                        return isDigit(character) || isDot(character) || isExponentialSymbol(character);
                    case States::Decimal:
                        return isDigit(character) || isExponentialSymbol(character);
                    case States::Exponential_1:
                        return isDigit(character) || isPlus(character) || isMinus(character);
                    case States::Exponential_2:
                        return isDigit(character);
                    case States::Closing:
                        return false;
                }
            }
Ejemplo n.º 5
0
Archivo: PolyDDV.cpp Proyecto: 8l/rose
bool PolyDDV::isIdenticalVector(PolyDDV& ddv)
{
  if (ddv.getSize() != _types.size())
    return false;
  int i;
  for (i = 0; i < ddv.getSize(); ++i)
    {
      if (ddv.isPlus(i) && ! isPlus(i))
	return false;
      else if (ddv.isMinus(i) && ! isMinus(i))
	return false;
      else if (ddv.isStar(i) && ! isStar(i))
	return false;
      else if (ddv.isEq(i) && ! isEq(i))
	return false;
      else if (ddv.isScalar(i))
	{
	  if (! isScalar(i) || getScalar(i) != ddv.getScalar(i))
	    return false;
	}
    }

  return true;
}
Ejemplo n.º 6
0
void region_division()
{
for(k=0;k<300;k++)
{
	lcd_print(1,9,k,4);
	if(flag[0]>1 && flag[1]>1 && flag[2]>1 && flag[3]>1)
	{
	 USART_Transmit('@');
	 USART_Transmit('r');
	 get_start=1;
	 cond=1;
	 break;
	}
	else if(get_start==1)
	{
	  break;
	 }
}
if(get_start==0)
{
for(k=0;k<100;k++)
{
	lcd_print(1,9,k,4);
	if(flag[0]>1 && flag[2]>1 && flag[1]>1) 
	{
	 USART_Transmit('@');
	 USART_Transmit('e');
	 get_start=1;
	 switch(bot_dir)
	 {
	 case N : cond = 1;break;
	 case S : cond =2;path[31]=M;break;
	 case E : break;
	 case W : cond = 1 ;break;
	 }
	 break;
	}
	else if(get_start==1)
	{
	 break;
	 }
}
}
if(get_start==0)
{
for(k=0;k<100;k++)
{
	lcd_print(1,9,k,4);
	if((flag[0]>1 && flag[2]>1) )
	{
	 USART_Transmit('@');
	 USART_Transmit('w');
	 get_start=1;
	 cond=2;
	 path[31]=M;
	 break;
	}
	else if(get_start==1)
	{
	 break;
	 }
}
}
if(get_start==0)
{
  if(flag[0]> 1 || flag[1]> 1 || flag[2]>1 || flag[3]>1)
  {
     USART_Transmit('@');
	  USART_Transmit('q');
		cond =2;
		get_start=1;
  }
}
if(get_start==1)
{			
	forward();
	while(1)
	{
		follow();
		if(isPlus())
		{
			if(block_found == 1)
			{
				block_detect();
				block_found =0;
			}
			if(isBlock1())
			{	
				block_found = 1;
			}
			if(cond == 1)
			{
			current_value = path1[pathindex++];
			orient(current_value);
			}
			else if(cond==2)
			{
			current_value = path[pathindex++];
			orient(current_value);
			}
		}
	}
  }
}
Ejemplo n.º 7
0
void orient(int value)
{
	switch(value)
	{

		case F:
			follow();
			while(isPlus());

				break;

		case L:
				turnLeft_done();
			if(bot_dir == N)
			{
				bot_dir = W;
			}
			else if (bot_dir == E)
			{
				bot_dir = N;
			}
			else if (bot_dir == W)
			{
				bot_dir=S;
			}
			else if (bot_dir == S)
			{
				bot_dir = E;
			}
				break;
		case R:
			turnRight_done();
		if(bot_dir == N)
			{
				bot_dir = E;
			}
			else if (bot_dir == E)
			{
				bot_dir =S;
			}
			else if (bot_dir == W)
			{
				bot_dir = N;
			}
			else if (bot_dir == S)
			{
				bot_dir = W;
			}
			break;
				
			case M: 
			
				check_task_completion();
				if(neigh ==1 || final_done ==1)
				{
					stop();
					_delay_ms(200000);
				}	
				else 
				{
					final_done=1;
					forward();
					turnRight1();
					path1[0]=R;
					pathindex=0;
					while(1)
					{
					follow();
						if(isPlus())
						{
						current_value = path1[pathindex++];
						orient(current_value);
						}
					}
				}
				break;
	}

}
Ejemplo n.º 8
0
 void dispersion()
 {
  to_begin=1;
 lcd_cursor(1,1);
  lcd_string("DISPE");
  velocity(VELOCITY_MAX,VELOCITY_MAX);
		forward();
		while(1)
		{
		follow();
		lcd_print(2,16,bot_dir,1);
			if(isPlus())
			{
					follow();
					while(isPlus());
					if(value == 0 && end == 0)		
					initial_direction(bot_id);	
					
					if(value == 0 && end == 1)
					{
						turnRight();
						change_dirn(bot_dir);
					}
				value++;
						
			}
			if(isEnd())
			{
				USART_Transmit('*');
				USART_Transmit(bot_id);
				switch(bot_id)
				{
				case 'A':	flag[0]++;break;
				case 'B':	flag[1]++;break;
				case 'C': 	flag[2]++;break;
				case 'D':	flag[3]++;break;
				}
				
				if(end==0)
				{
					turnBack();
					value = 0;
				
				}
				if(end==1)
				{  
					turnBack();
					value = 0;
				}
				if(end ==2)
				{
				length =value-1;
				lcd_print(1,7,length,1);
				turnBack();
				stop();
				break;
				}
				end++;
			  
			}
		}
}
//Main Function
int main()
{
	init_devices();
	init_encoders();
	lcd_set_4bit();
	lcd_init();
	int value=0;
	forward();
	velocity(130,130);
	lcd_print(2,1,130,3);
	lcd_print(2,5,130,3);
	lcd_print(2,9,pathindex,2);
	lcd_print(2,13,dirn,3);


	while(1)
	{	
		read_sensor();
		follow();
		
		if(isPlus())
		{	
			read_sensor();
			value = path[pathindex++];
			
			// Code inserted for calculation of actual location wrt initial starting point , 
			// It will consider direction also.

			if (value == F)
			{
				// Move the bot forward, for location only , No movement on ground.
				move_bot(FR);
			}
			else if (value == L)
			{
				// Move the bot left , for location only , No movement on ground.
				move_bot(LT);
			}
			else if (value == R)
			{
				// Move the bot right, for location only , No movement on ground.
				move_bot(RT);
			}
			else if (value == M)
			{
				// To stop the Bot and then break out
				stop();
				break;
			}
					
			orient(value);

/*			lcd_print(2,9,pathindex,2);
			lcd_print(2,13,dirn,3);
			lcd_print(1,13,turnL,1);
			lcd_print(1,15,turnR,1);
*/
			
		}
		
		if(turnL == 1)
		{/*
		lcd_print(1,13,turnL,1);
		forward_mm(20);
		stop();
		velocity(180,180);
		left_degrees(95);
		//_delay_ms(120);
		read_sensor();
		//	 while(Left_white_line <0x40)
		// {
		//	read_sensor();
		//	left();
		// }
		 stop();
	 	 forward();
		velocity(180,180);
		 turnL = 0;
		 */

		 back_mm(50);
		//stop();
		//velocity(130,130);
		stop();
		left_degrees(50);
		rotate_left_slowly();
	 	forward();
		velocity(130,130);
		turnL = 0;
		}
		
		if(turnR == 1)
		{
		/*
		lcd_print(1,15,turnR,1);
		forward_mm(20);
		stop();
		velocity(180,180);
		right_degrees(95);
		//_delay_ms(200);
		read_sensor();
		// while(Right_white_line <0x30)
		// {
		// read_sensor();
		// right();
		// }
		stop();
		forward();
		//follow();
		velocity(180,180);
		 turnR = 0;
		*/

		back_mm(50);
		//stop();
		//velocity(130,130);
		stop();
		right_degrees(50);
		rotate_right_slowly();
	 	forward();
		velocity(130,130);
		turnR = 0;
		}
	
	}


	// Three Beeps for Interval
	buzzer_on();
	_delay_ms(100);
	buzzer_off();
	_delay_ms(100);

	buzzer_on();
	_delay_ms(100);
	buzzer_off();
	_delay_ms(100);

	buzzer_on();
	_delay_ms(100);
	buzzer_off();
	_delay_ms(100);

	//code to head-back to starting position , i.e. Origin
	return_path_counter = reach_origin();
	
	forward();
	velocity(130,130);
	int counter = 0;
	int intermediate_value = 0;

	while(counter < return_path_counter)
	{	
		read_sensor();
		follow();
		
		if(isPlus())
		{	
			read_sensor();
			value = path_to_origin[counter];
			counter++;
			
			// Code inserted for calculation of actual location wrt initial starting point , 
			// It will consider direction also.

			if (intermediate_value == FR)
			{
				// Move the bot forward, for location only , No movement on ground.
				value = F;
			}
			else if (value == LT)
			{
				// Move the bot left , for location only , No movement on ground.
				value = L;
			}
			else if (value == RT)
			{
				// Move the bot right, for location only , No movement on ground.
				value = R;
			}
			else if (value == ST)
			{
				value = M;
				// specially inserted as break will not allow the bot to stop using "orient(value)".
				orient(value);
				break;
			}
					
			orient(value);
		
		}
		
		if(turnL == 1)
		{
		 back_mm(50);
		//stop();
		//velocity(130,130);
		stop();
		left_degrees(50);
		rotate_left_slowly();
	 	forward();
		velocity(130,130);
		turnL = 0;
		}
		
		if(turnR == 1)
		{
		back_mm(50);
		//stop();
		//velocity(130,130);
		stop();
		right_degrees(50);
		rotate_right_slowly();
	 	forward();
		velocity(130,130);
		turnR = 0;
		}
	
	}


	// Three beeps for Finish
	buzzer_on();
	_delay_ms(100);
	buzzer_off();
	_delay_ms(100);

	buzzer_on();
	_delay_ms(100);
	buzzer_off();
	_delay_ms(100);

	buzzer_on();
	_delay_ms(100);
	buzzer_off();
	_delay_ms(100);

}
void orient(int value)
{
	switch(value)
	{

		case F:
			
		
			while(isPlus())
			{
				read_sensor();
				follow();
			}

				break;

		case L:
				//turnLeft();
					turnL =1;
			if(dirn == N)
			{
			//	turnLeft();
				dirn = W;
			}
			else if (dirn == E)
			{
			//	turnBack();
				dirn = N;
			}
			else if (dirn == W)
			{
				dirn=S;
			}
			else if (dirn == S)
			{
			//	turnRight();
				dirn = E;
			}
				break;
		case R:
		//turnRight();
		turnR =1;
		if(dirn == N)
			{
				//turnRight();
				dirn = E;
			}
			else if (dirn == E)
			{
				dirn =S;
			}
			else if (dirn == W)
			{
				//turnBack();
				dirn = N;
			}
			else if (dirn == S)
			{
				//turnLeft();
				dirn = W;
			}
			
				break;
		case M:
		stop();
		
	}
	

}
Ejemplo n.º 11
0
/** int _OS_Regex(char *pattern, char *str, char **prts_closure,
              char **prts_str, int flags) v0.1
 * Perform the pattern matching on the pattern/string provided.
 * Returns 1 on success and 0 on failure.
 * If prts_closure is set, the parenthesis locations will be
 * written on prts_str (which must not be NULL)
 */              
char *_OS_Regex(char *pattern, char *str, char **prts_closure, 
              char **prts_str, int flags)
{
    char *r_code = NULL;
    
    int ok_here;
    int _regex_matched = 0;
    
    int prts_int;

    char *st = str;
    char *st_error = NULL;
    
    char *pt = pattern;
    char *next_pt;

    char *pt_error[4] = {NULL, NULL, NULL, NULL};
    char *pt_error_str[4];
    

    /* Will loop the whole string, trying to find a match */
    do
    {
        switch(*pt)
        {
            case '\0':
                if(!(flags & END_SET) || (flags & END_SET && (*st == '\0')))
                    return(r_code);
                break;

                /* If it is a parenthesis do not match against the character */
            case '(':
                /* Find the closure for the parenthesis */
                if(prts_closure)
                {
                    prts_int = 0;
                    while(prts_closure[prts_int])
                    {
                        if(prts_closure[prts_int] == pt)
                        {
                            prts_str[prts_int] = st;
                            break;
                        }
                        prts_int++;
                    }
                }

                pt++;
                if(*pt == '\0')
                {
                    if(!(flags & END_SET) || (flags & END_SET && (*st == '\0')))
                        return(r_code);
                }
                break;
        }

        /* If it starts on Backslash (future regex) */
        if(*pt == BACKSLASH)
        {
            if(Regex((uchar)*(pt+1), (uchar)*st))
            {
                next_pt = pt+2;
                
                /* If we don't have a '+' or '*', we should skip
                 * searching using this pattern.
                 */
                if(!isPlus(*next_pt))
                {
                    pt = next_pt;
                    if(!st_error)
                    {
                        /* If st_error is not set, we need to set it here.
                         * In case of error in the matching later, we need
                         * to continue from here (it will be incremented in
                         * the while loop)
                         */
                        st_error = st;
                    }
                    r_code = st;
                    continue;
                }
                
                /* If it is a '*', we need to set the _regex_matched
                 * for the first pattern even.
                 */
                if(*next_pt == '*')
                {
                    _regex_matched = 1;
                }


                /* If our regex matches and we have a "+" set, we will
                 * try the next one to see if it matches. If yes, we 
                 * can jump to it, but saving our currently location
                 * in case of error.
                 * _regex_matched will set set to true after the first
                 * round of matches
                 */
                if(_regex_matched)
                {
                    next_pt++;
                    ok_here = -1;

                    /* If it is a parenthesis, jump to the next and write
                     * the location down if 'ok_here >= 0'
                     */
                    if(prts(*next_pt))
                    {
                        next_pt++;
                    }
                    
                    if(*next_pt == '\0')
                    {
                        ok_here = 1;
                    }
                    else if(*next_pt == BACKSLASH)
                    {
                        if(Regex((uchar)*(next_pt+1), (uchar)*st))
                        {
                            /* If the next one does not have
                             * a '+' or '*', we can set it as
                             * being read and continue.
                             */
                            if(!isPlus(*(next_pt+2)))
                            {
                                ok_here = 2;
                            }
                            else
                            {
                                ok_here = 0;
                            }
                        }
                    }
                    else if(*next_pt == charmap[(uchar)*st])
                    {
                        _regex_matched = 0;
                        ok_here = 1;
                    }

                    /* If the next character matches in here */
                    if(ok_here >= 0)
                    {
                        if(prts_closure && prts(*(next_pt - 1)))
                        {
                            prts_int = 0;
                            while(prts_closure[prts_int])
                            {
                                if(prts_closure[prts_int] == (next_pt -1))
                                {
                                    if(*(st+1) == '\0')
                                        prts_str[prts_int] = st+1;
                                    else    
                                        prts_str[prts_int] = st;
                                    break;
                                }
                                prts_int++;
                            }
                        }


                        /* If next_pt == \0, return the r_code */
                        if(*next_pt == '\0')
                        {
                            continue;
                        }

                            
                        /* Each "if" will increment the amount
                         * necessary for the next pattern in ok_here
                         */
                        if(ok_here) 
                            next_pt+=ok_here;
                        
                        
                        if(!pt_error[0])
                        {
                            pt_error[0] = pt;
                            pt_error_str[0] = st;
                        }
                        else if(!pt_error[1])
                        {
                            pt_error[1] = pt;
                            pt_error_str[1] = st;
                        }
                        else if(!pt_error[2])
                        {
                            pt_error[2] = pt;
                            pt_error_str[2] = st;

                        }
                        else if(!pt_error[3])
                        {
                            pt_error[3] = pt;
                            pt_error_str[3] = st;
                        }

                        pt = next_pt;
                    }
                }
                else
                {
                    next_pt++;

                    /* If it is a parenthesis, mark the location */
                    if(prts_closure && prts(*next_pt))
                    {
                        prts_int = 0;
                        while(prts_closure[prts_int])
                        {
                            if(prts_closure[prts_int] == next_pt)
                            {
                                if(*(st+1) == '\0')
                                    prts_str[prts_int] = st +1;
                                else
                                    prts_str[prts_int] = st;
                                break;
                            }
                            prts_int++;
                        }
                        next_pt++;
                    }

                    _regex_matched = 1;
                }
                
                r_code = st;
                continue;
            }
            
            else if((*(pt+3) == '\0') && (_regex_matched == 1)&&(r_code))
            {
                r_code = st;
                if(!(flags & END_SET) || (flags & END_SET && (*st == '\0')))
                    return(r_code);
            }
            
            /* If we didn't match regex, but _regex_matched == 1, jump
             * to the next available pattern
             */
            else if((*(pt+2) == '+') && (_regex_matched == 1))
            {
                pt+=3;
                st--;
                _regex_matched = 0;
                continue;
            }
            /* We may not match with '*' */
            else if(*(pt+2) == '*')
            {
                pt+=3;
                st--;
                r_code = st;
                _regex_matched = 0;
                continue;
            }

            _regex_matched = 0;
        }
        else if(*pt == charmap[(uchar)*st])
        {
            pt++;
            if(!st_error)
            {
                /* If st_error is not set, we need to set it here.
                 * In case of error in the matching later, we need
                 * to continue from here (it will be incremented in
                 * the while loop)
                 */
                st_error = st;
            }
            r_code = st;
            continue;
        }

        /* Error Handling */
            if(pt_error[3])
            {
                pt = pt_error[3];
                st = pt_error_str[3];
                pt_error[3] = NULL;
                continue;
            }
            else if(pt_error[2])
            {
                pt = pt_error[2];
                st = pt_error_str[2];
                pt_error[2] = NULL;
                continue;
            }
            else if(pt_error[1])
            {
                pt = pt_error[1];
                st = pt_error_str[1];
                pt_error[1] = NULL;
                continue;
            }
            else if(pt_error[0])
            {
                pt = pt_error[0];
                st = pt_error_str[0];
                pt_error[0] = NULL;
                continue;
            }
            else if(flags & BEGIN_SET)
            {
                /* If we get an error and the "^" option is
                 * set, we can return "not matched" in here.
                 */
                return(NULL);
            }
            else if(st_error)
            {
                st = st_error;
                st_error = NULL;
            }
            pt = pattern;
            r_code = NULL;
        
    }while(*(++st) != '\0');


    /* Matching for a possible last parenthesis */
    if(prts_closure)
    {
        while(!prts(*pt) && *pt != '\0')
        {
            if(*pt == BACKSLASH && *(pt+2) == '*')
                pt+=3;
            else
                break;    
        }
        
        if(prts(*pt))
        {
            prts_int = 0;
            while(prts_closure[prts_int])
            {
                if(prts_closure[prts_int] == pt)
                {
                    prts_str[prts_int] = st;
                    break;
                }
                prts_int++;
            }
        }
    }

    /* Cleaning up */
    if(ENDOFFILE(pt) || 
        (*pt == BACKSLASH && 
        _regex_matched && 
        (pt+=2) && 
        isPlus(*pt) && 
        (pt++) &&
        ((ENDOFFILE(pt)) || 
        ((*pt == BACKSLASH) && 
        (pt+=2) && 
        (*pt == '*') && 
        (pt++) && 
        (ENDOFFILE(pt)) ))) ||
        (*pt == BACKSLASH &&
        (pt+=2) &&
        (*pt == '*') &&
        (pt++) &&
        ENDOFFILE(pt))
        ) 
    {
        return(r_code);
    }
   
    return(NULL);
}