bool unity_sgraph::save_graph(std::string target, std::string format) { log_func_entry(); try { if (format == "binary") { dir_archive dir; dir.open_directory_for_write(target); dir.set_metadata("contents", "graph"); oarchive oarc(dir); if (dir.get_output_stream()->fail()) { log_and_throw_io_failure("Fail to write"); } save(oarc); dir.close(); } else if (format == "json") { save_sgraph_to_json(get_graph(), target); } else if (format == "csv") { save_sgraph_to_csv(get_graph(), target); } else { log_and_throw("Unable to save to format : " + format); } } catch (std::ios_base::failure& e) { std::string message = "Unable to save graph to " + sanitize_url(target) + ": " + e.what(); log_and_throw_io_failure(message); } catch (std::string& e) { std::string message = "Unable to save graph to " + sanitize_url(target) + ": " + e; log_and_throw(message); } catch (...) { std::string message = "Unable to save graph to " + sanitize_url(target) + ": Unknown Error."; log_and_throw(message); } return true; }
void get_intern_set() { char *n[MAX_INTERN_SET],key[MAX_INTERN_SET],ch; int i,j; int count=Nintern_set; Window temp=main_win; if(count==0)return; for(i=0;i<Nintern_set;i++){ n[i]=(char *)malloc(256); key[i]='a'+i; sprintf(n[i],"%c: %s",key[i],intern_set[i].name); } key[count]=0; ch=(char)pop_up_list(&temp,"Param set",n,key,count,12,0,10,0, no_hint,info_pop,info_message); for(i=0;i<count;i++)free(n[i]); j=(int)(ch-'a'); if(j<0||j>=Nintern_set){ err_msg("Not a valid set"); return; } /* plintf(" Got set %d \n",j); */ get_graph(); extract_internset(j); chk_delay(); redraw_params(); redraw_ics(); reset_graph(); }
int main() { int i; int max, mid, min; while(scanf("%d",&n)==1,n) { memset(map,0,sizeof(map)); for(i = 0; i < n; i++) { scanf("%s",adj[i]); } get_graph(); min = 1;max = n; while(min<max) { memset(c,-1,sizeof(c)); mid = (max+min)/2; if(fit(0,mid)) max = mid; else min = mid+(min==mid); } printf("%d channel",min); if(min!=1) putchar('s'); puts(" needed."); } return 1; }
int main(){ int N,M; while(scanf("%d%d",&N,&M)!=EOF){ get_graph(N,M); run(); } return 0; }
void graphmgr::dirblemgrops::do_load () { tizgraph_ptr_t g_ptr (get_graph (std::string ())); if (g_ptr) { GMGR_OPS_BAIL_IF_ERROR (g_ptr, g_ptr->load (), "Unable to load the graph."); } p_managed_graph_ = g_ptr; }
void Init(int N,int M) { int i,j,u,v,w,px,py; get_graph(); nn1=(N+1)*(M+1); scr1=1;sink1=nn1;vn1=nn1+(N*M); //建图 for(i=1;i<=N+1;i++) { for(j=1;j<=M;j++) { w=Scan(); u=(i-1)*(M+1)+j; v=u+1; add_edge(u,v,w); //Insert(v,u,w); } } for(i=1;i<=N;i++) { for(j=1;j<=M+1;j++) { //scanf("%d",&w); w=Scan(); u=(i-1)*(M+1)+j; v=u+M+1; add_edge(u,v,w); //Insert(v,u,w); } } for(i=0;i<N;i++){ for(j=0;j<M;j++){ w=Scan(); add_edge(i*M+j+1+nn1,i*(M+1)+j+1,w); w=Scan(); add_edge(i*M+j+1+nn1,i*(M+1)+j+2,w); } for(j=0;j<M;j++){ w=Scan(); add_edge(i*M+j+1+nn1,(i+1)*(M+1)+j+1,w); w=Scan(); add_edge(i*M+j+1+nn1,(i+1)*(M+1)+j+2,w); } } }
/** * 读入并初始化一个图 * * @return 图的地址 * @author jianzhang.zj */ graph_type *read_graph() { int node_num, arc_num; printf("请输入图中节点的数量:\n"); scanf("%d", &node_num); printf("请输入图中边的数量:\n"); scanf("%d", &arc_num); graph_type *graph = get_graph(node_num, arc_num); printf("请输入图中所有的边:\n"); int i, u, v, value; for (i = 0; i < arc_num; i ++) { scanf("%d%d%d", &u, &v, &value); add_arc(graph, u, v, value); add_arc(graph, v, u, value); // 仅仅是无向图的时候需要添加反向边 } return graph; }
void unity_sgraph::save_reference(oarchive& oarc) const { log_func_entry(); oarc.write(GRAPH_MAGIC_HEADER, strlen(GRAPH_MAGIC_HEADER)); oarc << get_graph().get_num_partitions(); get_graph().save_reference(oarc); }