Пример #1
0
float MEA(plist *p, char *structure, double gamma) {

  int i,j,n;
  Litem *li;
  plist *pp, *pl;

  List *C;
  double MEA, *Mi, *Mi1, *tmp, *pu;
  struct MEAdat bdat;

  n = strlen(structure);
  for (i=0; i<n; i++) structure[i] = '.';

  pu = space(sizeof(double)*(n+1));
  pp = pl = prune_sort(p, pu, n, gamma);

  C = (List*) space((n+1)*(sizeof(List)));

  Mi = (double *) space((n+1)*sizeof(double));
  Mi1 = (double *) space((n+1)*sizeof(double));

  for (i=n; i>0; i--) {
    Mi[i] = pu[i];
    for (j=i+1; j<=n; j++) {
      double EA;
      Mi[j] = Mi[j-1] + pu[j];
      for (li=C[j].list; li<C[j].list+C[j].nelem; li++) {
	EA = li->A + Mi[(li->i) -1];
	Mi[j] = MAX2(Mi[j], EA);
      }
      if (pp->i == i && pp->j ==j) {
	EA = 2*gamma*pp->p +  Mi1[j-1];
	if (Mi[j]<EA) {
	  Mi[j]=EA;
	  pushC(&C[j], i, EA); /* only push into C[j] list if optimal */
	}
	pp++;
      }

    }
    tmp = Mi1; Mi1 = Mi; Mi = tmp;
  }

  MEA = Mi1[n];

  bdat.structure = structure; bdat.gamma = gamma;
  bdat.C = C;  bdat.Mi=Mi1; bdat.pl=pl; bdat.pu = pu;
  mea_backtrack(&bdat, 1, n, 0);
  free(Mi); free(Mi1); free(pl); free(pu);
  for (i=1; i<=n; i++)
    if (C[i].list) free(C[i].list);
  free(C);
  return MEA;
}
Пример #2
0
/* Handler del teclado */
void int_09() {
	char scancode;
	char eoi = EOI;
	_read(KEYBOARD, &scancode, 1);

	// We check if the scancode is a char or a control key.
	int flag = scancode >= 0x02 && scancode <= 0x0d;
	flag = flag || (scancode >= 0x10 && scancode <= 0x1b);
	flag = flag || (scancode >= 0x1E && scancode <= 0x29);
	flag = flag || (scancode >= 0x2b && scancode <= 0x35);
	if (flag)
		pushC(scanCodeToChar(scancode)); //guarda un char en el stack
	else
		controlKey(scancode); // Envia el scancode al analizador de control keys.

	_write(PIC1, &eoi, 1);
}
Пример #3
0
// Keyboard handler
void int_09() {
	krn++;
	char scancode;
	scancode = _in(0x60);

	// We check if the scancode is a char or a control key.
	int flag = scancode >= 0x02 && scancode <= 0x0d;
	flag = flag || (scancode >= 0x10 && scancode <= 0x1b);
	flag = flag || (scancode >= 0x1E && scancode <= 0x29);
	flag = flag || (scancode >= 0x2b && scancode <= 0x35);
	if (flag)	{
		char sc = scanCodeToChar(scancode);
		if(sc != 0 && sc != EOF)	{
			pushC(sc); 		  //guarda un char en el stack
		}
	}
	else {
		controlKey(scancode); // Envia el scancode al analizador de control keys.
	}
	
	kernel_buffer[0] = KILL;
	
	krn--;
}
Пример #4
0
int checkAny(int delimPairCount, char ** delimiters, long textLength, char * text){
	/*
	 *	The delimiter pairs should be entered in an order such that delimiters[even number] is the opening brackets
	 *	And the delimiters[odd number] is the closing brackets
	 */
	stack bookends;
	bookends.head = NULL;
	char * currentDelimiter;
	int textIndex, delimIndex, delimMatch, delimLen;
	for(textIndex = 0; textIndex < textLength; textIndex++){//go through the input file, character by character
		if(*(text + textIndex)==-1/*'ÿ'*/)//for some reason, a long string of "ÿÿÿÿÿÿÿÿ" kept showing up at the end of the file. I dunno why.
					break;

		printf("%c", *(text+textIndex));
		//if the character is a null terminating character, then break from the loop. that's the end of the file.
		//for each character:

		for(delimIndex = 0; delimIndex < (delimPairCount * 2); delimIndex++){//check against all possible opener/closer combinations.
			currentDelimiter = delimiters[delimIndex];//the current bracket in the delimiters array.

			if(text[textIndex]==currentDelimiter[0]){//if the first character of the delimiter matches,
				delimMatch = 1;//assume we have a match


				delimLen = strlen(currentDelimiter);//get the word length of the matching delimiter

				if(delimLen>1){//if the length of the delimiter is greater than one (like for "begin", which should be 5)
					int tempIndex = 1;

					while((tempIndex < delimLen) && textIndex+tempIndex < textLength){
						//check the rest of the delimiter against the following characters
						if(text[textIndex + tempIndex] != currentDelimiter[tempIndex]){
							delimMatch = 0;
							break;
						}
						tempIndex++;
					}
				}
				//printf("%d",delimMatch);

				if (delimMatch == 1) {//if we have a match between the text and a delimiter
					printf("%c", 163);
					if(delimIndex%2==0){//if the current char is an opener
						pushC(text[textIndex], &bookends);//add it to the stack
					}else{//otherwise, the delimiter is a closer.
						if(peek(&bookends)==delimiters[delimIndex-1][0]){//check to see if the top of the stack is a match

							pop(&bookends);//if the delimiters match, pop the stack
						}
						else{
							//if they do not match, then exit the function with a -1.
							printf("%c", peek(&bookends));
							//printf("%c", );
							return -1;
						}
					}
				}
			}//end if first characters match
		}
	}
	if(bookends.head!=NULL){
		return 1;
	}
	return 0;
}