示例#1
0
文件: quarkflow.c 项目: qiqi/pascal
void comp_graph_quarkflow(comp_graph_t * g)
{
    comp_graph_analyze(g);

    glp_graph * glp = glp_create_graph(sizeof(double)*2, sizeof(double)*4);
    _quarkflow_vertices_assemble(g, glp);
    _quarkflow_edges_assemble(g, glp);
    int ret_code = glp_mincost_okalg(
        glp, offsetof(v_data, rhs),
        offsetof(a_data, low), offsetof(a_data, cap), offsetof(a_data, cost),
        NULL, offsetof(a_data, x), offsetof(v_data, pi)
    );
    if (ret_code) {
        fprintf(stderr, "glp_mincost_okalg ret_code = %d\n", ret_code);
        exit(-1);
    }
    int base_potential = (int)node(glp->v[1])->pi;
    for (int i_vertex = 0; i_vertex < g->num_vertices; ++i_vertex) {
        int c_i = i_vertex*3+2;
        int d_i = i_vertex*3+3;
        int e_i = i_vertex*3+4;
        g->cde[i_vertex][0] = (int)node(glp->v[c_i])->pi - base_potential;
        g->cde[i_vertex][1] = (int)node(glp->v[d_i])->pi - base_potential;
        g->cde[i_vertex][2] = (int)node(glp->v[e_i])->pi - base_potential;
    }
}
示例#2
0
int main(int argc, char *argv[]){
  if(argc != 2){
    printf("usage: %s filename\n", argv[0]);
    return 1;
  }
  if(access(argv[0], R_OK) == -1) {
    printf("file %s is not readable!", argv[1]);
    return 1;
  }
  glp_graph *G;
  glp_vertex *v, *w;
  glp_arc *a;
  int i, ret;
  double sol;
  G = glp_create_graph(sizeof(v_data), sizeof(a_data));
  ret = glp_read_mincost(G,
			 offsetof(v_data, rhs),
			 offsetof(a_data, low),
			 offsetof(a_data, cap),
			 offsetof(a_data, cost),
			 argv[1]);
  if (ret) {
    return ret;
  }
  ret = glp_mincost_okalg(G,
			  offsetof(v_data, rhs),
			  offsetof(a_data, low),
			  offsetof(a_data, cap),
			  offsetof(a_data, cost),
			  &sol,
			  offsetof(a_data, x),
			  offsetof(v_data, pi));
  printf("ret = %d; sol = %5g\n", ret, sol);
  if (ret) {
    return ret;
  }
  for (i = 1; i <= G->nv; i++) {
    v = G->v[i];
    for (a = v->out; a != NULL; a = a->t_next) {
      w = a->head;
      printf("arc %d->%d: x = %5g; lambda = %5g\n",
	     v->i,
	     w->i,
	     arc(a)->x,
	     arc(a)->cost - (node(v)->pi - node(w)->pi));
    }
  }
  glp_delete_graph(G);
  return 0;
}