static int buildNetwork (CPXENVptr env, CPXNETptr net, WidgetGraph* widgetNet, int nnodes, int narcs, double * &supply, int* &head, int* &tail, double* &obj, double* &ub, double* &lb) { int status = 0; /* definitions to improve readability */ # define inf CPX_INFBOUND if ( CPXNETgetnumnodes (env, net) > 0 ) { status = CPXNETdelnodes (env, net, 0, CPXNETgetnumnodes (env, net)-1); if ( status ) goto TERMINATE; } /* Set optimization sense */ status = CPXNETchgobjsen (env, net, CPX_MAX); if ( status ) goto TERMINATE; /* Add nodes to network along with their supply values, but without any names. */ status = CPXNETaddnodes (env, net, nnodes, supply, NULL); if ( status ) goto TERMINATE; /* Add arcs to network along with their objective values and bounds, but without any names. */ status = CPXNETaddarcs (env, net, narcs, tail, head, lb, ub, obj, NULL); if ( status ) goto TERMINATE; // if (supply != NULL){ // cout << "before exit build, supply not empty" << endl; // } TERMINATE: return (status); }
int CplexAdapterBase::BuildNetwork(const Graph& g) { status_ = 0; /* Delete existing network. This is not necessary in this context since we know we have an empty network object. Notice that CPXNETdelnodes deletes all arcs incident to the deleted nodes as well. Therefore this one function call effectively deletes an existing network problem. */ if ( CPXNETgetnumnodes (env_, net_) > 0 ) { status_ = CPXNETdelnodes (env_, net_, 0, CPXNETgetnumnodes (env_, net_)-1); if ( status_ ) { return status_; }; } /* Set optimization sense */ status_ = CPXNETchgobjsen (env_, net_, CPX_MIN); if ( status_ ) { return status_; }; /* Add nodes to network along with their supply values, but without any names. */ status_ = CPXNETaddnodes (env_, net_, g.vertex_count, &g.vertex_supply[0], NULL); if ( status_ ) { return status_; }; /* Add arcs to network along with their objective values and bounds, but without any names. */ status_ = CPXNETaddarcs (env_, net_, g.edge_count, &g.edge_tails[0], &g.edge_heads[0], &g.edge_capacity_lower_bounds[0], &g.edge_capacity_uppper_bounds[0], &g.edge_costs[0], NULL); if ( status_ ) { return status_; }; return 0; }