BOOL readEntryFromFile(FILE *f, BOOK_ENTRY *entry)
{
    BOOL rc;
    UINT64 r;
    
    rc = readNumberFromFile(f, 8, &r);
    if(rc != TRUE) 
        return FALSE;
    
    entry->key=r;

    rc = readNumberFromFile(f, 2, &r);
    if(rc != TRUE ) 
        return FALSE;
        
    entry->move=r;
    
    rc= readNumberFromFile(f, 2, &r);
    if(rc != TRUE) 
        return FALSE;
        
    entry->weight=r;
    
    rc= readNumberFromFile(f, 4, &r);
    if(rc != TRUE) 
        return FALSE;
        
    entry->learn=r;
    
    return TRUE;
}
示例#2
0
int main(int argc, char * * argv)
{
  //Verify that the correct number of arguments is given
  if(argc != 2)
    FATAL("Invalid number of command line arguments!");
  //Open the map file for reading
  FILE * map = fopen(argv[1], "r");
  //Read the number of vertices in the file
  int numVertices = readNumberFromFile(map);
  //Read the number of edges in the file
  int numEdges = readNumberFromFile(map);
  //Read vertice data and assign it to nodal linked list "vertex"
  int nodenum = readNumberFromFile(map);
  int nodexcoord = readNumberFromFile(map);
  int nodeycoord = readNumberFromFile(map);
  Node * vertex = nodeConstructor(nodenum, nodexcoord, nodeycoord);
  int i;
  Node * tmpitr = vertex;
  for(i = 1; i < numVertices; ++i) {
    nodenum = readNumberFromFile(map);
    nodexcoord = readNumberFromFile(map);
    nodeycoord = readNumberFromFile(map);
    tmpitr->next = nodeConstructor(nodenum, nodexcoord, nodeycoord);
    tmpitr = tmpitr->next;
  }
  //Read edge data from the file and assign it to respective lists
  for(i = 0; i < numEdges; ++i) {
    int firstnode = readNumberFromFile(map);
    int secondnode = readNumberFromFile(map);
    insertConnection(vertex, firstnode, secondnode);
  }
  //Print adjacency relationships
  tmpitr = vertex;
  EdgeList * itrEdge = NULL;
  while(tmpitr != NULL) {
    printf("%d: ", tmpitr->value);
    itrEdge = tmpitr->edges;
    while(itrEdge != NULL) {
      printf("%d ", itrEdge->connectedto);
      itrEdge = itrEdge->next;
    }
    printf("\n");
    tmpitr = tmpitr->next;
  }

  return EXIT_SUCCESS;
}
示例#3
0
int * readQueries(FILE * query, int numQueries)
{
  int i;
  int * retArr = malloc(sizeof(int) * 2 * numQueries);
  for(i = 0; i < (2 * numQueries); ++i) {
    retArr[i] = readNumberFromFile(query);
  }
  return retArr;
}
示例#4
0
void cGame::InitQuestions()
{
	const char *kFileName = "database.txt";
	const Uint32 kDataPieces = 6;
	for(int questionNum = 0; questionNum < kAmountOfQuestions; ++questionNum)
	{
		cQuestion *pQuestion = new cQuestion();

		pQuestion->mQuestion = readStringFromFile(kFileName, questionNum, kDataPieces, 0);
		pQuestion->mAnswer1 = readStringFromFile(kFileName, questionNum, kDataPieces, 1);
		pQuestion->mAnswer2 = readStringFromFile(kFileName, questionNum, kDataPieces, 2);
		pQuestion->mAnswer3 = readStringFromFile(kFileName, questionNum, kDataPieces, 3);
		pQuestion->mAnswer4 = readStringFromFile(kFileName, questionNum, kDataPieces, 4);
		pQuestion->mCorrectAnswer = readNumberFromFile(kFileName, questionNum, kDataPieces, 5);

		mList.push_back( pQuestion );
	}
}
void txGeneAccession(char *oldBedFile, char *lastIdFile, char *newBedFile, char *txToAccFile,
	char *oldToNewFile)
/* txGeneAccession - Assign permanent accession number to genes. */
{
/* Read in all input. */
struct bed *oldList = bedLoadNAll(oldBedFile, 12);
verbose(2, "Read %d from %s\n", slCount(oldList), oldBedFile);
struct bed *newList = bedLoadNAll(newBedFile, 12);
verbose(2, "Read %d from %s\n", slCount(newList), newBedFile);
int txId = readNumberFromFile(lastIdFile);
verbose(2, "Last txId used was %d (from %s)\n", txId, lastIdFile);

/* Make a random-access data structure for old list. */
struct hash *oldHash = bedsIntoKeeperHash(oldList);

/* Make a little hash to help prevent us from reusing an
 * old accession twice (which might happen if we extend it
 * in two incompatible ways). */
struct hash *usedHash = hashNew(16);

/* Record our decisions in hash as well as file. */
struct hash *idToAccHash = hashNew(16);

/* Loop through new list first looking for exact matches. Record
 * exact matches in hash so we don't look for them again during
 * the next, "compatable" match phase. */
struct hash *oldExactHash = hashNew(16), *newExactHash = hashNew(16);
struct bed *oldBed, *newBed;
FILE *f = mustOpen(txToAccFile, "w");
FILE *fOld = mustOpen(oldToNewFile, "w");
for (newBed = newList; newBed != NULL; newBed = newBed->next)
    {
    oldBed = findExact(newBed, oldHash, usedHash);
    if (oldBed != NULL)
        {
	hashAdd(oldExactHash, oldBed->name, oldBed);
	hashAdd(newExactHash, newBed->name, newBed);
	hashAdd(usedHash, oldBed->name, NULL);
        fprintf(f, "%s\t%s\n", newBed->name, oldBed->name);
	hashAdd(idToAccHash, newBed->name, oldBed->name);
	fprintf(fOld, "%s:%d-%d\t%s\t%s\t%s\n", oldBed->chrom, oldBed->chromStart, oldBed->chromEnd,
		oldBed->name, oldBed->name, "exact");
	}
    }

/* Loop through new bed looking for compatible things.  If
 * we can't find anything compatable, make up a new accession. */
for (newBed = newList; newBed != NULL; newBed = newBed->next)
    {
    if (!hashLookup(newExactHash, newBed->name))
	{
	oldBed = findCompatible(newBed, oldHash, usedHash);
	if (oldBed == NULL)
	    {
	    char newAcc[16];
	    txGeneAccFromId(++txId, newAcc);
	    strcat(newAcc, ".1");
	    fprintf(f, "%s\t%s\n", newBed->name, newAcc);
	    hashAdd(idToAccHash, newBed->name, cloneString(newAcc));
	    oldBed = findMostOverlapping(newBed, oldHash);
	    char *oldAcc = (oldBed == NULL ? "" : oldBed->name);
	    fprintf(fOld, "%s:%d-%d\t%s\t%s\t%s\n", newBed->chrom, newBed->chromStart, newBed->chromEnd,
	    	oldAcc, newAcc, "new");
	    }
	else
	    {
	    char *acc = cloneString(oldBed->name);
	    char *ver = strchr(acc, '.');
	    if (ver == NULL)
	        errAbort("No version found in %s", oldBed->name);
	    *ver++ = 0;
	    int version = sqlUnsigned(ver);
	    char newAcc[16];
	    safef(newAcc, sizeof(newAcc), "%s.%d", acc, version+1);
	    hashAdd(usedHash, oldBed->name, NULL);
	    fprintf(f, "%s\t%s\n", newBed->name, newAcc);
	    hashAdd(idToAccHash, newBed->name, newAcc);
	    fprintf(fOld, "%s:%d-%d\t%s\t%s\t%s\n", newBed->chrom, newBed->chromStart, newBed->chromEnd,
	    	oldBed->name, newAcc, "compatible");
	    }
	}
    }
carefulClose(&f);

/* Make a random-access data structure for old list. */
struct hash *newHash = bedsIntoKeeperHash(newList);

/* Write record of ones that don't map. */
for (oldBed = oldList; oldBed != NULL; oldBed = oldBed->next)
    {
    if (!hashLookup(usedHash, oldBed->name))
	{
	char *newAcc = "";
	struct bed *newBed = findMostOverlapping(oldBed, newHash);
	if (newBed != NULL)
	    newAcc = hashMustFindVal(idToAccHash, newBed->name);
	fprintf(fOld, "%s:%d-%d\t%s\t%s\t%s\n", oldBed->chrom, oldBed->chromStart, oldBed->chromEnd,
		oldBed->name, newAcc, "lost");
	}
    }
carefulClose(&fOld);

if (!optionExists("test"))
    {
    FILE *fId = mustOpen(lastIdFile, "w");
    fprintf(fId, "%d\n", txId);
    carefulClose(&fId);
    }
}
示例#6
0
int main(int argc, char * * argv)
{
  //Verify that the correct number of arguments is given
  if(argc != 3)
    FATAL("Invalid number of command line arguments!");
  //Open the map file for reading
  FILE * map = fopen(argv[1], "r");
  //Read the number of vertices in the file
  int numVertices = readNumberFromFile(map);
  //Read the number of edges in the file
  int numEdges = readNumberFromFile(map);
  //Read vertice data and assign it to nodal linked list "vertex"
  int nodenum = readNumberFromFile(map);
  int nodexcoord = readNumberFromFile(map);
  int nodeycoord = readNumberFromFile(map);
  Node * vertex = nodeConstructor(nodenum, nodexcoord, nodeycoord);
  int i;
  Node * tmpitr = vertex;
  for(i = 1; i < numVertices; ++i) {
    nodenum = readNumberFromFile(map);
    nodexcoord = readNumberFromFile(map);
    nodeycoord = readNumberFromFile(map);
    tmpitr->next = nodeConstructor(nodenum, nodexcoord, nodeycoord);
    tmpitr = tmpitr->next;
  }
  //Read edge data from the file and assign it to respective lists
  for(i = 0; i < numEdges; ++i) {
    int firstnode = readNumberFromFile(map);
    int secondnode = readNumberFromFile(map);
    insertConnection(vertex, firstnode, secondnode);
  }
  fclose(map);
  //NOTE: At this point, the graph is complete, so begin algorithm
  //Open the query file for reading
  FILE * query = fopen(argv[2], "r");
  //Read the number of queries
  int numQueries = readNumberFromFile(query);
  //Read query data and store it for reference
  int * queryArr = readQueries(query, numQueries);
  //Store origin node in list
  Node * origin = vertex;
  //Loop through the queries
  for(i = 0; i < (numQueries * 2); i += 2) {
    //Find the starting point of the query
    int startVal = queryArr[i];
    int endVal = queryArr[i+1];
    //If they're the same, avoid trying to do anything else
    if(startVal == endVal) {
      printf("0\n");
      printf("%d %d\n", startVal, endVal);
    }
    else {
      Node * start = findVertexByValue(startVal, origin);
      Node * end = findVertexByValue(endVal, origin);
      start->weight = 0;
      while(areAllNotRemoved(origin)) {
	//Set the weight check to find minimum node
	Node * itrNode = findLowestNode(origin);
	//Make sure we're not done
	if(itrNode->value == endVal)
	  break;
	//Update weights for adjacent nodes
	updateAdjacentWeights(itrNode, origin);
      }
      if(end->weight == PSEUDOINF)
	FATAL("Final node weight was not updated... possibly unconnected?");
      //Produce the result list
      ResultList * results = reslistConstructor(end->value, end->weight);
      Node * before = findVertexByValue(end->prev, origin);
      while(before->value != startVal) {
	ResultList * pinonfront = reslistConstructor(before->value, before->weight);
	pinonfront->next = results;
	results = pinonfront;
	before = findVertexByValue(before->prev, origin);
      }
      //Make sure the first number in the list is origin
      if(results->value != startVal) {
	ResultList * pinonfront2 = reslistConstructor(startVal, start->weight);
	pinonfront2->next = results;
	results = pinonfront2;
      }
      //Verify weights and assign the end weight
      //end->weight = verifyWeightsAndAssign(results, origin);
      //Print the final results
      printf("%ld\n", end->weight);
      ResultList * printitr = results;
      while(printitr != NULL) {
	printf("%d ", printitr->value);
	printitr = printitr->next;
      }
      printf("\n");
      reslistDestroy(results);
      resetGraph(origin);
    }
  }

  //Free used memory
  fclose(query);
  free(queryArr);
  nodeDestroy(origin);

  return EXIT_SUCCESS;
}