예제 #1
0
int main(int argc, char ** argv){
  int ret, i;
  
  if( (ret=loadFile(argv[1])) < 0){
    fprintf(stderr, "input file format error '%s' (ret=%d).\n", argv[1], ret);
    return -1;
  }
#if DEBUG_LOADFILE
  fprintf(stderr, "loadFile: %d\n", ret);
  fprintf(stderr, "nNodes: %d\n", nNodes);
  fprintf(stderr, "nEdges: %d\n", nEdges);
  fprintf(stderr, "graphWeight: %d\n", graphWeight);
  printEdgeAdj();
  printEdgeNames();
  printEdgeWeights();
#endif

  if (nEdges == nNodes){
    //must be hamiltonian cycle if it is strongly connected
    //and problem statement said that we could assume it was
    updateOptimumSoln(graphWeight);
    printAnswer();
    return DONE;
  }

  for(i=0; i<nNodes; i++)
    dijkstra_single_source_shortest_paths(i);

#if DEBUG_MEGBB
  printMinPaths();
#endif
  //initialize stuff and do first pass solution
  megbbinit();

  //if we can't delete any edges or we have already found the theoretically 
  //minimum solution in the first pass (sum of min weight edges from each row)
  //we're done
  if( (nEbar == 0) || (minSumRows[0] == (graphWeight - sumEbarprime)) )
    goto done;
  
  megbb(EdgesAdjTail);
 
 done:
  printAnswer();
  //cleanup for good form
  freeEdges(EdgesAdjHead);
  EdgesAdjHead = EdgesAdjTail = EdgesNameHead = EdgesCostHead = NULL;
  return (0);
}
예제 #2
0
파일: test.c 프로젝트: frostiee22/COMP3000
// recursive printing of path
void printAnswer(int * Data, int m, int n,int i, int j){
    if(i==0 && j==0) printf("%d\n",*(Data));
    if( (i==m-1) && (j==n-1) ) return;
    
	int east = *((Data+(i)*(n+1)) + (j+1));
	int south = *((Data+(i+1)*(n+1)) + (j));
	
	if(east > south){
		printf("E");
		printAnswer((int*)Data,m,n,i,j+1);
	}
	else{
		printf("S");
		printAnswer((int*)Data,m,n,i+1,j);
	}
}
예제 #3
0
파일: test.c 프로젝트: frostiee22/COMP3000
int main(){
    
    FILE *in = fopen("input.txt","r");
    FILE *out = fopen("output.txt","w");
    
    int m,n,i,j;
    fscanf(in,"%d %d",&m,&n);
    int Data[m+1][n+1];
    
    for (i=0; i<m;i++)
    	for(j=0; j<n;j++)
    		fscanf(in,"%d",&Data[i][j]);
    		
    fclose(in);
    
	// pad data	for computation	
	for(i=0;i<=m;i++)
		Data[i][n] = 0;
	for(j=0;j<=n;j++)
		Data[m][j] = 0;
	
    Compute((int*)Data,m,n);
    printAnswer((int*)Data,m,n,0,0);
    
    fclose(out);
    return 0;
}
예제 #4
0
int main() { 
	size_t sizeRows = 0;
	size_t sizeColumns = 0; 
	std::vector<float> inputMatrix; 
	std::vector<float> inputVector; 
	std::vector<float> answer; 

	readLinearEquations(inputMatrix, inputVector, sizeRows, sizeColumns);  	
 
	Matrix a(inputMatrix, sizeRows, sizeColumns);
	LinearVector b(inputVector);
	SystemLinearEquations lin(a, b);
	lin.JacodMethod();
	answer = lin.getAnswer();

	printAnswer(answer);
} 
예제 #5
0
void backtrack(int column){
	int row;

	if (column > size){
		if (remaining){
			printAnswer();
			remaining--;
		}
		answer++;
		return;
	}

	for (row = 0; row < size; row++){
		if (canUse(row,column)){
			used[row] = column;
			backtrack(column+1);
			used[row] = 0;
		}
	}
}
예제 #6
0
파일: path.c 프로젝트: HyeonIl/univ_study
//==========================================
int main(void)
{
	int testCase;
	number = 1;

	input = fopen("path.inp", "r");
	output = fopen("path.out", "w");

	fscanf(input, "%d", &testCase);

	while (testCase--){
		fscanf(input, "%d %d %d", &M, &N, &K);
		inputData();
		
		findAnswer();
		printAnswer();
		initData();		
	}

	fclose(input);
	fclose(output);
	return 0;
}
예제 #7
0
void GridGraph::printQuiz(std::ostream& os) const {
    printAnswer(os, std::set<ArcNumber>());
}
예제 #8
0
/*********************************
 *
 * Main()
 *
 *********************************/
int main(int argc, char ** argv){
  int ret, i, j;
  
  if( (ret=loadFile(argv[1])) < 0){
    fprintf(stderr, "input file format error '%s' (ret=%d).\n", argv[1], ret);
    return -1;
  }
#if DEBUG_LOADFILE
  fprintf(stderr, "loadFile: %d\n", ret);
  fprintf(stderr, "nNodes: %d\n", nNodes);
  fprintf(stderr, "nEdges: %d\n", nEdges);
  fprintf(stderr, "graphWeight: %d\n", graphWeight);
  printEdgeAdj();
  printEdgeNames();
  printEdgeWeights();//desc order
#endif

  if (nEdges == nNodes){
    //must be hamiltonian cycle if it is strongly connected
    //and problem statement said that we could assume it was
    printAnswer();
    goto done;
  }
  
  maxOutDegree = 0;
  ret = 0;
  for (i=0; i<nNodes; i++)
    {
      for(j=0; j<nNodes; j++)
	if (A[i][j].m != NULL)
	  ret ++;
      
      if (ret > maxOutDegree)
	maxOutDegree = ret;
    }

  //if the ratio of edges to nodes is < 2n use megbb
  //for(i=0; i<nNodes; i++)
  //  dijkstra_single_source_shortest_paths(i);
  //printMinPaths();

  /*for(i=0; i<nNodes; i++)*/{
    uniqueVisited = 0;
    //reset visited list
    for(j = 0;j<nNodes; j++)     
      visited[j] = 0;
    
    for(j = 0;j<nEdges; j++)     
      visitedLastCross[j] = 0;
    
    //best = graphWeight;//reset this
    startNode = 0;
    walk2(startNode, 0);
    //printAnswer();
  }
  printAnswer();

 done:
  //cleanup for good form
  freeEdges(EdgesAdjHead);
  EdgesAdjHead = EdgesNameHead = EdgesCostHead = NULL;
  
  return (0);
}