MC_ising_cycles.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 "CoinSort.hpp"
5 
6 #include "BCP_matrix.hpp"
7 
8 #include "MC_cut.hpp"
9 
10 static inline void
11 MC_test_ising_four_cycle(const double sum, const double minviol,
12  const int c0, const int c1, const int c2,const int c3,
14 {
15  // sort c0, c1, c2
16  int cut[4];
17  cut[3] = c3;
18  if (c0 < c1) {
19  if (c0 < c2) {
20  cut[0] = c0;
21  if (c1 < c2) {
22  cut[1] = c1;
23  cut[2] = c2;
24  } else {
25  cut[1] = c2;
26  cut[2] = c1;
27  }
28  } else {
29  cut[0] = c2;
30  cut[1] = c0;
31  cut[2] = c1;
32  }
33  } else {
34  if (c1 < c2) {
35  cut[0] = c1;
36  if (c0 < c2) {
37  cut[1] = c0;
38  cut[2] = c2;
39  } else {
40  cut[1] = c2;
41  cut[2] = c0;
42  }
43  } else {
44  cut[0] = c2;
45  cut[1] = c1;
46  cut[2] = c0;
47  }
48  }
49 
50  if (sum > 2 + minviol) {
51  cuts.push_back(new MC_cycle_cut(cut, 3, 4));
52  double row[4] = {1.0, 1.0, 1.0, -1.0};
53  CoinSort_2(cut, cut+4, row);
54  rows.push_back(new BCP_row(cut, cut+4, row, row+4, -BCP_DBL_MAX, 2));
55  } else if (sum < - minviol) {
56  std::rotate(cut, cut+3, cut+4);
57  cuts.push_back(new MC_cycle_cut(cut, 1, 4));
58  double row[4] = {1.0, -1.0, -1.0, -1.0};
59  CoinSort_2(cut, cut+4, row);
60  rows.push_back(new BCP_row(cut, cut+4, row, row+4, -BCP_DBL_MAX, 0));
61  }
62 }
63 
64 void
65 MC_test_ising_four_cycles(const int n, const int* cycles,
66  const double* x, const double minviol,
68 {
69  const int* cycle = cycles;
70  for (int i = 0; i < n; ++i) {
71  const int c0 = cycle[0];
72  const int c1 = cycle[1];
73  const int c2 = cycle[2];
74  const int c3 = cycle[3];
75  const double x0 = x[c0];
76  const double x1 = x[c1];
77  const double x2 = x[c2];
78  const double x3 = x[c3];
79 
80  MC_test_ising_four_cycle(x0+x1+x2-x3, minviol, c0, c1, c2, c3, cuts, rows);
81  MC_test_ising_four_cycle(x1+x2+x3-x0, minviol, c1, c2, c3, c0, cuts, rows);
82  MC_test_ising_four_cycle(x2+x3+x0-x1, minviol, c2, c3, c0, c1, cuts, rows);
83  MC_test_ising_four_cycle(x3+x0+x1-x2, minviol, c3, c0, c1, c2, cuts, rows);
84 
85  cycle += 4;
86  }
87 }
88 
89 //#############################################################################
90 
91 void
92 MC_test_ising_triangles(const int n, const int* cycles,
93  const double* x, const double minviol,
95 {
96  const int* cycle = cycles;
97  int cut[3];
98  for (int i = 0; i < n; ++i) {
99  const int c0 = cycle[0];
100  const int c1 = cycle[1];
101  const int c2 = cycle[2];
102  const double x0 = x[c0];
103  const double x1 = x[c1];
104  const double x2 = x[c2];
105 
106  if (x0+x1+x2 > 2 + minviol) {
107  cuts.push_back(new MC_cycle_cut(cycle, 3, 3));
108  double row[3] = {1.0, 1.0, 1.0};
109  rows.push_back(new BCP_row(cycle, cycle+3, row, row+3, -BCP_DBL_MAX, 2));
110  }
111  if (+ x0 - x1 - x2 > minviol) {
112  cuts.push_back(new MC_cycle_cut(cycle, 1, 3));
113  double row[3] = {1.0, -1.0, -1.0};
114  rows.push_back(new BCP_row(cycle, cycle+3, row, row+3, -BCP_DBL_MAX, 0));
115  }
116  if (- x0 + x1 - x2 > minviol) {
117  cut[0] = c1;
118  cut[1] = c0;
119  cut[2] = c2;
120  cuts.push_back(new MC_cycle_cut(cut, 1, 3));
121  double row[3] = {-1.0, 1.0, -1.0};
122  rows.push_back(new BCP_row(cycle, cycle+3, row, row+3, -BCP_DBL_MAX, 0));
123  }
124  if (- x0 - x1 + x2 > minviol) {
125  cut[0] = c2;
126  cut[1] = c0;
127  cut[2] = c1;
128  cuts.push_back(new MC_cycle_cut(cut, 1, 3));
129  double row[3] = {-1.0, -1.0, 1.0};
130  rows.push_back(new BCP_row(cycle, cycle+3, row, row+3, -BCP_DBL_MAX, 0));
131  }
132 
133  cycle += 3;
134  }
135 }
ULong x2
Definition: OSdtoa.cpp:1776
void push_back(const_reference x)
Append x to the end of the vector.
#define BCP_DBL_MAX
Definition: BCP_math.hpp:6
ULong * x0
Definition: OSdtoa.cpp:1776
static void MC_test_ising_four_cycle(const double sum, const double minviol, const int c0, const int c1, const int c2, const int c3, BCP_vec< BCP_cut * > &cuts, BCP_vec< BCP_row * > &rows)
ULong x1
Definition: OSdtoa.cpp:1776
void MC_test_ising_triangles(const int n, const int *cycles, const double *x, const double minviol, BCP_vec< BCP_cut * > &cuts, BCP_vec< BCP_row * > &rows)
void fint * n
void MC_test_ising_four_cycles(const int n, const int *cycles, const double *x, const double minviol, BCP_vec< BCP_cut * > &cuts, BCP_vec< BCP_row * > &rows)
void fint fint fint real fint real * x
This class holds a row in a compressed form.
Definition: BCP_matrix.hpp:152