コード例 #1
0
core_solver_pretty_printer<T, X>::core_solver_pretty_printer(lp_core_solver_base<T, X > & core_solver, std::ostream & out):
    m_out(out),
    m_core_solver(core_solver),
    m_column_widths(core_solver.m_A.column_count(), 0),
    m_A(core_solver.m_A.row_count(), vector<string>(core_solver.m_A.column_count(), "")),
    m_signs(core_solver.m_A.row_count(), vector<string>(core_solver.m_A.column_count(), " ")),
    m_costs(ncols(), ""),
    m_cost_signs(ncols(), " "),
    m_rs(ncols(), zero_of_type<X>()) {
    m_w_buff = new T[m_core_solver.m_m];
    m_ed_buff = new T[m_core_solver.m_m];
    m_core_solver.save_state(m_w_buff, m_ed_buff);
    init_m_A_and_signs();
    init_costs();
    init_column_widths();
    init_rs_width();
    m_cost_title = "costs";
    m_basis_heading_title = "heading";
    m_x_title = "x*";
    m_title_width = std::max(std::max(m_cost_title.size(), std::max(m_basis_heading_title.size(), m_x_title.size())), m_approx_norm_title.size());
}
コード例 #2
0
 BestTree(Self& r, VertexCostMap mu_, VertexPredMap pi_, EdgeCostMap ec,
          BestTreeOptionsParsed const& bestOpt = BestTreeOptions())
     : tu(r)
     , g(tu.g)
     , opt(bestOpt)
     , mu(mu_)
     , pi(pi_)
     , loc(tu.vert_fact.template init<heap_loc_t>())
     , locp(loc)
     , remain(tu.edge_fact.template init<Ntails>())
     , remain_pmap(remain)
     , ec(ec)
     , rereachptr(opt.allow_rereach ? RereachPtr(new Rereach(g, 0)) : RereachPtr())
     , rereach(opt.allow_rereach ? rereachptr->pmap : RereachP())
     , heap(mu, locp) {
   opt.parse();
   copy_pmap(edgeT, g, remain_pmap, tu.unique_tails_pmap);
   // visit(edgeT, g, make_indexed_pair_copier(remain_pmap, tu.unique_tails_pmap, ec)); // pair(rem)<-(tr,
   // ev)
   init_costs();
 }
コード例 #3
0
void parse_topology(char *filename)
{
  int i, index;
  int ip[4];
  uint16_t my_id, neighbor_id, cost;
  
  // Open the file in read mode
  FILE *file;
  file = fopen(filename, "r");

  init_costs();

  // Read the number of servers and numbers of neighbors
  if (fscanf(file, "%d", &topology.num_servers) != 1) die ("Cannot read number of neighbors from topology file");
  if (fscanf(file, "%d", &topology.num_neighbors) != 1) die ("Cannot read number of neighbors from topology file");

  // Read each server's id, ip, and port, and store the index too
  for (i = 0; i < topology.num_servers; ++i)
  {
    // Read the server id, ip, and port, or die if the file is not formatted properly
    if (fscanf(file, "%" SCNu16 " %d.%d.%d.%d %" SCNu16 "\n", &(topology.server[i].id), &ip[0], &ip[1], &ip[2], &ip[3],
      &(topology.server[i].port)) != 6) die("Could not read server info from topology file");
    
    // Store the info in the topology struct
    topology.server[i].ip[0] = ip[0];
    topology.server[i].ip[1] = ip[1];
    topology.server[i].ip[2] = ip[2];
    topology.server[i].ip[3] = ip[3];
    topology.server[i].index = i;
  }

  // Read the neighbor link costs... start by finding ourselves in the list of servers
  if (fscanf(file, "%" SCNd16 " %" SCNu16 " %" SCNu16 "\n", &my_id, &neighbor_id, &cost) != 3)
    die("Could not read neighbor link costs from topology file");
  
  // Set up a pointer to our own current host
  my_server = (struct server_info *)get_server_from_id(my_id);
  if (my_server == NULL) die ("Could not find my server in topology list");
  
  // Initialize neighbor costs to infinity
  for (i = 0; i < MAX_SERVERS; ++i)
    my_server->cost[i] = INFINITY;

  // Add the first neighbor's cost/link to the my_server struct
  index = get_index_from_id(neighbor_id);
  my_server->link[index] = get_server_from_id(neighbor_id);
  my_server->cost[index] = cost;

  // Now read in the rest of the neighbor costs
  for (i = 1; i < topology.num_neighbors; ++i)
  {
    // Make sure the file is well-formed: has 3 entries per line and the first host id is consistent
    if (fscanf(file, "%" SCNu16 " %" SCNu16 " %" SCNu16 "\n", &my_id, &neighbor_id, &cost) != 3)
      die("Could not read neighbor link costs from topology file");
    if (my_id != my_server->id) die ("Mismatched server ID in neighbor cost data in topology file");
    
    // Add each neighbor's cost/link to the my_server struct
    index = get_index_from_id(neighbor_id);
    my_server->link[index] = get_server_from_id(neighbor_id);
    my_server->cost[index] = cost;
  }
}