weight_t graph_maxflow(graph_t*graph, node_t*pos1, node_t*pos2) { int max_flow = 0; graphcut_workspace_t* w = graphcut_workspace_new(graph, pos1, pos2); graph_reset(graph); DBG check_graph(graph); posqueue_addpos(w->queue1, pos1); w->flags1[pos1->nr] |= ACTIVE|IN_TREE; posqueue_addpos(w->queue2, pos2); w->flags2[pos2->nr] |= ACTIVE|IN_TREE; DBG workspace_print(w); while(1) { path_t*path; while(1) { char done1=0,done2=0; node_t* p1 = posqueue_extract(w->queue1); if(!p1) { graphcut_workspace_delete(w); return max_flow; } DBG printf("extend 1 from %d (%d edges)\n", NR(p1), node_count_edges(p1)); path = expand_pos(w, w->queue1, p1, 0, w->flags1, w->flags2); if(path) break; DBG workspace_print(w); #ifdef TWOTREES node_t* p2 = posqueue_extract(w->queue2); if(!p2) { graphcut_workspace_delete(w); return max_flow; } DBG printf("extend 2 from %d (%d edges)\n", NR(p2), node_count_edges(p2)); path = expand_pos(w, w->queue2, p2, 1, w->flags2, w->flags1); if(path) break; DBG workspace_print(w); #endif } DBG printf("found connection between tree1 and tree2\n"); DBG path_print(path); DBG printf("decreasing weights\n"); max_flow += decrease_weights(graph, path); DBG workspace_print(w); DBG printf("destroying trees\n"); combust_tree(w, w->queue1, w->queue2, path); DBG workspace_print(w); DBG check_graph(w->graph); path_delete(path); } graphcut_workspace_delete(w); return max_flow; }
/* get attributes */ static int tag_getattr(const char *user_path, struct stat *stbuf) { int res; print_log(_("getattr '%s'\n"), user_path); struct path *path = path_create(user_path, 0); res = getattr_intra(path, stbuf); print_log(_("getattr returning '%s'\n"), strerror(-res)); path_delete(path); return res; }
int fd_close(struct file_descriptor *fd) { int err = 0; if (close(fd->fh) < 0) err = -errno; path_delete(fd->path); free(fd); return err; }
void test_open_unlink(int argc, char** argv){ bj_ostream& os = bj_out; if(argc < 2){ os << "Faltan agrs !!" << bj_eol; } ch_string the_pth = argv[1]; ch_string oper = argv[2]; ch_string full_pth = path_to_absolute_path(the_pth); if(oper == "d"){ ch_string top_pth = TEST_ROOT_PATH; ch_string full_pth = path_to_absolute_path(the_pth); os << "DELETING " << full_pth << " ..." << bj_eol; path_delete(full_pth, top_pth); } else { std::ifstream istm; istm.open(the_pth.c_str(), std::ios::binary); if(istm.good() && istm.is_open()){ os << "File " << the_pth << " OK. Type ENTER ..." << bj_eol; getchar(); istm.seekg (0, std::ios::end); long file_sz = istm.tellg(); istm.seekg (0, std::ios::beg); if(file_sz < 0){ os << "ERROR 1" << bj_eol; abort_func(1); } BRAIN_CK(sizeof(char) == 1); char* file_content = tpl_malloc<char>(file_sz + 1); istm.read(file_content, file_sz); long num_read = istm.gcount(); if(num_read != file_sz){ os << "ERROR 2" << bj_eol; abort_func(1); } file_content[file_sz] = 0; ch_string fdat = file_content; tpl_free<char>(file_content, file_sz + 1); os << fdat << bj_eol; istm.close(); } else { os << "Could NOT open file " << the_pth << bj_eol; } } }