Esempio n. 1
0
void printPath(TreeNode* root, TreeNode* target_leaf){
  if (root == NULL)
    return NULL;
    
  if (root == target_leaf || printPath(root->left, target_leaf) || printPath(root->right, target_leaf)){
    printf ("%d", root->data);
    return true;
  }
  
  return false;
}
Esempio n. 2
0
void Magnusson::insertSwapArcsForNewUsedPath(TrackingAlgorithm::Path &p)
{
    /* Swap Arc Insertion: walk along path
     * - find alternative incoming arcs of the traversed node, where there are also multiple outgoing arcs of the previous node
     * - insert swap arc between any alternative pair of nodes connected to the path by in / out arcs.
    */
    for(Path::iterator it = p.begin(); it != p.end(); ++it)
    {
        switch((*it)->getType())
        {
            // do not add swap arcs for division or dummy
            case Arc::Division:
            case Arc::Dummy:
                break;
            case Arc::Move:
                insertMoveSwapArcs(*it);
                break;
            case Arc::Appearance:
                insertAppearanceSwapArcs(*it);
                break;
            case Arc::Disappearance:
                insertDisappearanceSwapArcs(*it);
                break;
            case Arc::Swap:
            {
                printPath(p);
                throw std::runtime_error("There should not be swap arcs left after cleaning up the path");
            }
        }
    }
}
Esempio n. 3
0
int main(int argc, char *argv[]) {
	int i, j,k;
	int u, v, w;

	FILE *fin = fopen("./tmp/graph", "r");
	fscanf(fin, "%d", &e);
	for (i = 0; i < e; ++i)
		for (j = 0; j < e; ++j)
			dist[i][j] = 0;
	n = -1;
	for (i = 0; i < e; ++i) {
		fscanf(fin, "%d%d%d", &u, &v, &w);
		dist[u][v] = w;
		dist[v][u] = w;
		n = MAX(u, MAX(v, n));
	}
	fclose(fin);
	
	for(k=1 ; k <= n;k++){
		dijkstra(k);

		for (i = 1; i <= n; ++i) {
			dst=i;
			if(k==i)
				continue;
			printPath(i,dst);
			dst =0;
		}
	}
	return 0;
}
Esempio n. 4
0
int main() {

    while (scanf("%d%d", &total_length, &track_number) != EOF) {
        for (int i = 1; i <= track_number; i++) {
            scanf("%d", &track[i]);
        }
        memset(dp, 0, sizeof(dp));
        memset(pre, -1, sizeof(pre));
        dp[0] = 1;
        for (int i = 1; i <= track_number; i++) {
            for (int j = total_length; j >= track[i]; j--) {
                if (dp[j - track[i]] == 1) {
                    dp[j] = 1;
                    if (pre[j] == -1) {
                        pre[j] = i;
                    }
                }
            }
        }
        int i;
        for (i = total_length; i >= 1; i--) {
            if (dp[i] == 1) {
                break;
            }
        }
        printPath(i);
        printf("sum:%d\n", i);
    }
    return 0;
}
Esempio n. 5
0
int main(int argc,char* argv[]){
    
    printPath(".");
    printf("\n");
    exit(1);

}
Esempio n. 6
0
void testGetCurrentCycle() {
    uint8_t array[] = {3, 1, 3, 1, 2, 3};
    uint8_t clockSize = 6;
    printf("\n====================\n");
    printf("get current cycle\n");
    printf("====================\n");
    printf("new test with: ");
    printClock(array, clockSize);
    SearchTreeNode *stn1 = newSearchTreeNode(NULL, array + 1);
    SearchTreeNode *stn0 = newSearchTreeNode(stn1, array);
    SearchTreeNode *stn3 = newSearchTreeNode(stn0, array + 3);
    SearchTreeNode *stn4 = newSearchTreeNode(stn3, array + 4);
    SearchTreeNode *stn2 = newSearchTreeNode(stn4, array + 2);
    SearchTreeNode *stn5 = newSearchTreeNode(stn2, array + 5);
    GArray * path = getCurrentPath(stn5);
    printf("assert that path has the length of the clock\n");
    assert(path->len == clockSize);
    SearchTreeNode *pathnode = &g_array_index(path, SearchTreeNode, 0);
    printf("assert that the first element of the path is stn1\n");
    assert(stn1->content == pathnode->content);
    pathnode = &g_array_index(path, SearchTreeNode, clockSize - 1);
    printf("assert that the last element of the path is stn5\n");
    assert(stn5->content == pathnode->content);

    printPath(path, array);

    printf("add stn1 as child of stn5 (create contradiction)\n");
    SearchTreeNode *stnLast = newSearchTreeNode(stn5, array + 1);
    printf("assert that contradicted path is null\n");
    path = getCurrentPath(stnLast);
    assert(path == NULL);
    printf("assert that incomplete path is not null\n");
    path = getCurrentPath(stn4);
    assert(path != NULL && path->len < clockSize);
}
Esempio n. 7
0
int main()
	{
		int n,i,j;
		printf("\nEnter the number of total Node in Graph:");
		scanf("\n%d",&n) ;
		printf("\nEnter the distance between vertices.....\nIf no edge put 99(say infinity):\n\n");
		for(i=0;i<n;i++)
		   {
			   for(j=0;j<n;j++)
			      {
					  printf("\nEnter value for Graph[%d][%d]:",i,j);
					  scanf("%d",&graph[i][j]);
				  }
		   }
		 for(i=0;i<n;i++)
			{
			  for(j=0;j<n;j++)
			    {
				  if(i==j)
				    path[i][j]=-1;
				  else
				    path[i][j]=i;
				}
			}
		   display(graph,n);
		   floydWarshall(graph,n);
		   printf("\nAfter Algo Appiled: \n");
		   display(graph,n);
		   printPath(path,n);
		   printf("\nPath Without Recursion:\n");
		   printPathWithoutRecursive(path,n);
	return 0;
	}
Esempio n. 8
0
void Dijkstra(MGraph* G, int v) {
    int min_d, u, i, j;
    for (i = 0; i < G->n; i++) {
        s[i] = 0;
        d[i] = G->E[v][i];
        path[i] = (d[i] < INFI) ? v : -1;
    }
    s[v] = 1;
    
    for (i = 0; i < G->n; i++) {
        min_d = INFI;
        for (j = 0; j < G->n; j++)
            if (s[j] == 0 && d[j] < min_d) 
            { min_d = d[j];  u = j; }
        s[u] = 1;

        for (j = 0; j < G->n; j++) {
            if (d[u] + G->E[u][j] < d[j]) {
                d[j] = d[u] + G->E[u][j];
                path[j] = u;
            }
        }
    }

    printPath(G, v);
}
Esempio n. 9
0
int main(int argc, char *argv[]) {
    int i, j;
    int u, v, w;

    FILE *fin = fopen("dist.txt", "r");
    fscanf(fin, "%d", &e);
    for (i = 0; i < e; ++i)
        for (j = 0; j < e; ++j)
            dist[i][j] = 0;
    n = -1;
    for (i = 0; i < e; ++i) {
        fscanf(fin, "%d%d%d", &u, &v, &w);
        dist[u][v] = w;
        n = MAX(u, MAX(v, n));
    }
    fclose(fin);

    dijkstra(1);

    printD();

    printf("\n");
    for (i = 1; i <= n; ++i) {
        printf("Path to %d: ", i);
        printPath(i);
        printf("\n");
    }

    return 0;
}
Esempio n. 10
0
void printDTree(dTree* node, int depth) {
    dTree* current = node;
    if (depth==0){
        printf("root is %i\n", current->index);
    }
    printf("\n");
    for(int i =0; i< depth; i++){
            printf("\t");
    }
    printf("Node index: %i\n", current->index);
    for(int i =0; i< depth; i++){
            printf("\t");
    }
    printf("Node maxOverlap %i\n", current->overlap);
    for(int i =0; i< depth; i++){
            printf("\t");
    }
    printf("Node totalOverlap %i\n", current->totalOverlap);
    for(int i =0; i< depth; i++){
            printf("\t");
    }
    depth++;
    if(current->path != NULL){
        printPath(current->path);
    }
    if(current->xTraversal != NULL){
        printDTree(current->xTraversal, depth);
    }
    if(current->yTraversal != NULL){
        printDTree(current->yTraversal, depth);
    }
}
Esempio n. 11
0
// cf. http://msdn.microsoft.com/en-us/library/cc144148(v=vs.85).aspx
static bool WriteExtendedFileExtensionInfo(HKEY hkey)
{
    bool success = true;

    ScopedMem<WCHAR> exePath(GetInstalledExePath());
    if (HKEY_LOCAL_MACHINE == hkey)
        success &= WriteRegStr(hkey, L"Software\\Microsoft\\Windows\\CurrentVersion\\App Paths\\" EXENAME, NULL, exePath);

    // mirroring some of what DoAssociateExeWithPdfExtension() does (cf. AppTools.cpp)
    ScopedMem<WCHAR> iconPath(str::Join(exePath, L",1"));
    success &= WriteRegStr(hkey, REG_CLASSES_APPS L"\\DefaultIcon", NULL, iconPath);
    ScopedMem<WCHAR> cmdPath(str::Format(L"\"%s\" \"%%1\" %%*", exePath));
    success &= WriteRegStr(hkey, REG_CLASSES_APPS L"\\Shell\\Open\\Command", NULL, cmdPath);
    ScopedMem<WCHAR> printPath(str::Format(L"\"%s\" -print-to-default \"%%1\"", exePath));
    success &= WriteRegStr(hkey, REG_CLASSES_APPS L"\\Shell\\Print\\Command", NULL, printPath);
    ScopedMem<WCHAR> printToPath(str::Format(L"\"%s\" -print-to \"%%2\" \"%%1\"", exePath));
    success &= WriteRegStr(hkey, REG_CLASSES_APPS L"\\Shell\\PrintTo\\Command", NULL, printToPath);
    // don't add REG_CLASSES_APPS L"\\SupportedTypes", as that prevents SumatraPDF.exe to
    // potentially appear in the Open With lists for other filetypes (such as single images)

    // add the installed SumatraPDF.exe to the Open With lists of the supported file extensions
    for (int i = 0; NULL != gSupportedExts[i]; i++) {
        ScopedMem<WCHAR> keyname(str::Join(L"Software\\Classes\\", gSupportedExts[i], L"\\OpenWithList\\" EXENAME));
        success &= CreateRegKey(hkey, keyname);
        // TODO: stop removing this after version 1.8 (was wrongly created for version 1.6)
        keyname.Set(str::Join(L"Software\\Classes\\", gSupportedExts[i], L"\\OpenWithList\\" APP_NAME_STR));
        DeleteRegKey(hkey, keyname);
    }

    // in case these values don't exist yet (we won't delete these at uninstallation)
    success &= WriteRegStr(hkey, REG_CLASSES_PDF, L"Content Type", L"application/pdf");
    success &= WriteRegStr(hkey, L"Software\\Classes\\MIME\\Database\\Content Type\\application/pdf", L"Extension", L".pdf");

    return success;
}
Esempio n. 12
0
int main(void){
  FILE *fp = fopen("input.txt","r");
  if(fp == NULL){
    printf("No file found.\n");
    for(;;);
  }
  qBack = (queueElement **)malloc(sizeof(queueElement **));
  qFront = (queueElement **)malloc(sizeof(queueElement **));
  (*qBack) = NULL;
  (*qFront)= NULL;
  int nextInt;
  bool currentAr[BOARDSIZE];
  unsigned short firstBoard;

  int i;
  for (i = 0; i < BOARDSIZE; i++) *(currentAr + i) = false;
  nextInt = readNextInt(fp);
  initializeArray(nextInt, currentAr, fp);
  firstBoard=boolToShort(currentAr);
  parent[firstBoard] = firstBoard;
  hitPosition[firstBoard] = 0;

  for (i = 0; i < BOARDSIZE;i++)
    board[firstBoard][i] = currentAr[i];
  unsigned short emptyBoard = bfs(firstBoard);
  printf("done bfs, empty board is board number: %d, first board: %d\n", emptyBoard, firstBoard);
  printPath(emptyBoard, firstBoard);
  fclose(fp);
  return 0;
}
Esempio n. 13
0
bool ShaderBuild::parse(std::string file, FileBits& sourceBits, Defines& defs, std::vector<std::string> path)
{
	int fileBitStart = (int)sourceBits.size();
	
	//maintain include stack
	path.push_back(file);

	//detect infinite include
	for (int i = (int)path.size() - 1; i >= 0; --i)
	{
		int f = (int)path[i].find(":");
		if (f > 0 && path[i].substr(0,f) == file)
		{
			std::cout << printPath(path);
			std::cout << "Error: " << "Include loop" << ": " << file << std::endl;
			return false;
		}
	}
	
	//if the file has already been parsed, simply append the references to the bits we already have
	//don't add to the cache if #defines haven't been injected yet
	if (!firstContentLine && parseCache.find(file) != parseCache.end())
	{
		sourceBits.insert(sourceBits.end(), parseCache[file].begin(), parseCache[file].end());
		return true;
	}

	//buffer from memory or file
	std::streambuf* ifileBuff;

	//check if the source has already been supplied
	std::map<std::string, const char*>::iterator override;
	override = includeOverrides.find(file);
Esempio n. 14
0
int main(void) {
	int i, j;
	int found_src, found_dest;
	char src_name[MAXNAME + 1];
	char dest_name[MAXNAME + 1];
	int distance;
	
	while (scanf("%s to %s = %d", src_name, dest_name, &distance) != EOF) {
		found_src = found_dest = 0;
		min_distance += distance;
		
		for (i = 0; i < size; i++) {
			if (!strcmp(src_name, locations[i].name)) {
				found_src = 1;
				break;
			}
		}
		
		for (j = 0; j < size; j++) {
			if (!strcmp(dest_name, locations[j].name)) {
				found_dest = 1;
				break;
			}
		}
		
		if (!found_src) {
			i = newLocation(src_name);
		}
		
		if (!found_dest) {
			j = newLocation(dest_name);
		}
		
		addConnection(&locations[i], &locations[j], distance);
	}
	
	for(i = 0; i < size; i++)
		tryPath(locations + i, 0, 0);
	
	printf("Minimum path: %d\n", min_distance);
	printPath(min_path, size);
	
	printf("Maximum path: %d\n", max_distance);
	printPath(max_path, size);

	return 0;
}
// A utility function that prints all nodes on the path from root to target_leaf
bool printPath (struct node *root, struct node *target_leaf)
{
    // base case
    if (root == NULL)
        return false;

    // return true if this node is the target_leaf or target leaf is present in
    // one of its descendants
    if (root == target_leaf || printPath(root->left, target_leaf) ||
            printPath(root->right, target_leaf) )
    {
        printf("%d ", root->data);
        return true;
    }

    return false;
}
Esempio n. 16
0
void printPath(int parent[],int j)
{
  if(parent[j]==-1)
    return;
  printPath(parent,parent[j]);
  printf("%d ",j);


}
Esempio n. 17
0
int Graph::printPath(list<Vertex>::iterator vertex)
{
    if (vertex->Path != Unpath)
    {
        list<list<Vertex> >::iterator v = findV(vertex);
        printPath(v->begin());
    }
    return 0;
}
Esempio n. 18
0
void Graph::printPath( const Vertex & dest ) const
{
    if( dest.path != NULL )
    {
        printPath( *dest.path );
        cout << " to ";
    }
    cout << dest.name;
}
Esempio n. 19
0
void Aligner::alignPartExhaustive(){
	vector<pair<string,string>> multiread;
	vector<uNumber> path;
	string read,header;
	bool overlapFound(false);
	while(!readFile.eof()){
		readMutex.lock();
		{
			getReads(multiread,10000);
		}
		readMutex.unlock();
		for(uint i(0);i<multiread.size();++i){
			header=multiread[i].first;
			read=multiread[i].second;
			overlapFound=false;
			if(pathOption){
				path=alignReadExhaustivePath(read,overlapFound,errorsMax);
			}else{
				path=alignReadExhaustive(read,overlapFound,errorsMax);
			}
			if(path.size()!=0){
				pathMutex.lock();
				{
					printPath(path);
				}
				pathMutex.unlock();
			}else{
				if(!overlapFound){
					noOverlapMutex.lock();
					{
						noOverlapFile<<header<<endl<<read<<endl;
						//~ notMappedFile<<read<<endl;
					}
					noOverlapMutex.unlock();
				}else{
					notMappedMutex.lock();
					{
						notMappedFile<<header<<endl<<read<<endl;
						//~ notMappedFile<<read<<endl;
					}
					notMappedMutex.unlock();
				}
			}
		}
		if(iter++%10==0){
			cout<<"Read : "<<readNumber<<endl;
			cout<<"No Overlap : "<<noOverlapRead<<" Percent : "<<(100*float(noOverlapRead))/readNumber<<endl;
			cout<<"Got Overlap : "<<alignedRead+notAligned<<" Percent : "<<(100*float(alignedRead+notAligned))/readNumber<<endl;
			cout<<"Overlap and Aligned : "<<alignedRead<<" Percent : "<<(100*float(alignedRead))/(alignedRead+notAligned)<<endl;
			cout<<"Overlap but no aligne: "<<notAligned<<" Percent : "<<(100*float(notAligned))/(alignedRead+notAligned)<<endl;
			auto end=chrono::system_clock::now();auto waitedFor=end-startChrono;
			cout<<"Reads/seconds : "<<readNumber/(chrono::duration_cast<chrono::seconds>(waitedFor).count()+1)<<endl;
			cout<<"Overlap per reads : "<<(overlaps)/(alignedRead+notAligned)<<endl;
			cout<<endl;
		}
	}
}
Esempio n. 20
0
void printPath(struct node* node){
    if (node->name == 16){
        printf(" %d END ! \n", node->name);
    }
    else{
        printf(" %d ->", node->name);
        printPath(node->child);
    }
}
void DijkstraRouter::print() const
{
    printf("Constructed dijkstra path of length %d for link %s between %s and %s as follows:\n",
            path.size(),
            link->getName().c_str(),
            link->getFirst()->getName().c_str(),
            link->getSecond()->getName().c_str());
    printPath(path);
}
Esempio n. 22
0
void bfsFindExit(Maze &M)
{
	queue <Position> Q;
	
	vector<vector<Position> > pred;
	init_table(pred, M.size, NULLPOS);
	Position current, nbr;
	stack<Position> path;
	current = M.start;
	M.visit(current);
	Q.push(current);
	
	while (true)
	{
		/* First condition if the current position is the exit*/
		if (current == M.exitpos)
		{
			cout << endl;
			printPath(pred, current);
			return;

		}
		/* Checking if current is a wall*/
		if (current == NULLPOS)
		{
			cout << "Now way out" << endl;
			return;

		}
		/* Getting the first open neighbor */
		nbr = M.getOpenNeighbor(current);
		/* If neighbor is a wall*/
		if (nbr == NULLPOS)
		{
			Q.pop();
			current = Q.front();
			
			continue;
		}
		/* Otherwise set entry and visit neighbor*/
		else
		{
			setEntry(pred, nbr, current);
			M.visit(nbr);
			current = nbr;
			Q.push(nbr);
		}

		
		

	}
	
	
	system("PAUSE");

}
Esempio n. 23
0
/* Отпечатва върховете от минималния път и връща дължината му */
unsigned printPath(unsigned j) {
	unsigned count = 1;

	if (pred[j] > -1) {
		count += printPath(pred[j]);
	}
	printf("%c ", j + 'A'); /* Oтпечатва поредния връх от намерения път */

	return count;
}
Esempio n. 24
0
void printQueue(Node* head){
	Node *curr = head;
	printf("Queue Start ");
	while(curr != NULL){
		printPath(curr->value);
		curr = curr->nextNode;
		printf("|||");
	}
	printf("Queue End \n");
}
// A utility function to print the constructed distance
// array
int printSolution(int dist[], int n, int parent[])
{
    int src = 0;
    printf("Vertex\t  Distance\tPath");
    for (int i = 1; i < V; i++)
    {
        printf("\n%d -> %d \t\t %d\t\t%d ", src, i, dist[i], src);
        printPath(parent, i);
    }
}
// Function to print shortest path from source to j
// using parent array
void printPath(int parent[], int j)
{
    // Base Case : If j is source
    if (parent[j]==-1)
        return;

    printPath(parent, parent[j]);

    printf("%d ", j);
}
Esempio n. 27
0
void printTreeAncestor(node* root, int *arrPath, int level) {
	if (root == NULL)
		return;

	arrPath[level] = root->data;
	printPath(root->data, arrPath,level);

	printTreeAncestor(root->left, arrPath, level+1);
	printTreeAncestor(root->right,arrPath,level+1);
}
Esempio n. 28
0
 /**
  * Prints the path to the node
  * @param node Node or target
  */
void ShortPath::printPath(int node){

    if(node == source)
        cout << node << "..";
    else if(elements[node].get_predecessor() == -1)
        cout << "No path from "<<source<< " to "<< node <<endl;
    else {
        printPath(elements[node].get_predecessor());
        cout << node <<"..";
    }
}
Esempio n. 29
0
void printPath(FILE* out, Graph G, int s, int v) {
    int p = getParent(G, v);
    if(v == s) {
        fprintf(out, "%d ", s);
    } else if(p == NIL) {
        fprintf(out, "No %d-%d path exists\n", s, v);
    } else {
        printPath(out, G, s, p);
        fprintf(out, "%d ", v);
    }
}
Esempio n. 30
0
int main() {

	//printGrid();
	bool found = findPath(0,0, row-1, col-1);
	if (found)
		printPath();
	else
		std::cout << "No path found .. " << std::endl;


}