MC_mst_heur.cpp
Go to the documentation of this file.
1 // Copyright (C) 2000, International Business Machines
2 // Corporation and others. All Rights Reserved.
3 
4 #include "CoinHelperFunctions.hpp"
5 #include "CoinSort.hpp"
6 
7 #include "BCP_vector.hpp"
8 #include "MC.hpp"
9 #include "MC_cut.hpp"
10 #include "MC_solution.hpp"
11 
13 MC_mst_heur(const MC_problem & mc, const double * x, const double * w,
14  const double alpha, const double beta,
15  const MC_EdgeOrdering edge_ordering,
16  const int heurswitchround,
17  const bool do_edge_switch_heur, const int struct_switch_heur)
18 {
19  MC_solution* sol;
20 
21  const int m = mc.num_edges;
22  const int n = mc.num_nodes;
23 
24  BCP_vec<int> nodesign(n, 1);
25  int * edgeorder = new int[m];
26  int * edges_in_tree = new int[n-1];
27  double * composite_weight = new double[m];
28 
29  int j;
30  switch (edge_ordering) {
32  if (w == NULL || beta == 0.0) {
33  for (j = 0; j < m; ++j)
34  composite_weight[j] = alpha * x[j];
35  } else {
36  for (j = 0; j < m; ++j)
37  composite_weight[j] = alpha * x[j] - beta * w[j];
38  }
39  break;
41  if (w == NULL || beta == 0.0) {
42  for (j = 0; j < m; ++j)
43  composite_weight[j] = alpha * (1.0-x[j]);
44  } else {
45  for (j = 0; j < m; ++j)
46  composite_weight[j] = alpha * (1.0-x[j]) - beta * w[j];
47  }
48  break;
50  if (w == NULL || beta == 0.0) {
51  for (j = 0; j < m; ++j)
52  composite_weight[j] = alpha * CoinMin(x[j], 1.0-x[j]);
53  } else {
54  for (j = 0; j < m; ++j)
55  composite_weight[j] = alpha*CoinMin(x[j], 1.0-x[j]) - beta*w[j];
56  }
57  break;
58  }
59  CoinIotaN(edgeorder, m, 0);
60 
61  CoinSort_2(composite_weight, composite_weight + m, edgeorder);
62 
63  MC_kruskal(mc, edgeorder, x, nodesign.begin(), edges_in_tree);
64 
65  delete[] composite_weight;
66  delete[] edges_in_tree;
67  delete[] edgeorder;
68 
69  sol = new MC_solution(nodesign, mc, heurswitchround,
70  do_edge_switch_heur, struct_switch_heur);
71  return sol;
72 }
73 
int num_edges
Definition: MC.hpp:92
int num_nodes
Definition: MC.hpp:91
iterator begin()
Return an iterator to the beginning of the object.
Definition: BCP_vector.hpp:99
void MC_kruskal(const MC_problem &mc, const int *edgeorder, const double *x, int *nodesign, int *edges_in_tree)
Definition: MC_kruskal.cpp:33
static char * j
Definition: OSdtoa.cpp:3622
real alpha
MC_solution * MC_mst_heur(const MC_problem &mc, const double *x, const double *w, const double alpha, const double beta, const MC_EdgeOrdering edge_ordering, const int heurswitchround, const bool do_edge_switch_heur, const int struct_switch_heur)
Definition: MC_mst_heur.cpp:13
void fint * m
void fint fint fint real fint real real real real real real real real * w
void fint * n
MC_EdgeOrdering
Definition: MC_cut.hpp:26
void fint fint fint real fint real * x