HOG2
GraphInconsistencyInstances.cpp
Go to the documentation of this file.
1 //
2 // GraphInconsistencyInstances.cpp
3 // Inconsistency
4 //
5 // Created by Nathan Sturtevant on 2/19/19.
6 // Copyright © 2019 NS Software. All rights reserved.
7 //
8 
10 #include "GraphEnvironment.h"
11 
13 
14  // This graph is from Mero, 1984
15  Graph *GetPolyGraph(int numExampleNodes)
16  {
17  Graph *g = new Graph();
18  node *n;
19 
20  n = new node("S");
21  n->SetLabelL(kHeuristic, 0);
22  g->AddNode(n);
26 
27  n = new node("m");
28  n->SetLabelL(kHeuristic, 0);
29  g->AddNode(n);
33 
34  char nodeName[2] = {'a', 0};
35  for (int x = 0; x < numExampleNodes; x++)
36  {
37  n = new node(nodeName);
38  nodeName[0]++;
39  n->SetLabelL(kHeuristic, numExampleNodes+x);
40 
41  n->SetLabelF(GraphSearchConstants::kXCoordinate, -0.8+1.6*(double(x)/(numExampleNodes-1.0)));
44 
45  g->AddNode(n);
46  g->AddEdge(new edge(0, n->GetNum(), 1));
47  g->AddEdge(new edge(n->GetNum(), 1, numExampleNodes-x));
48  }
49 
50  nodeName[0] = 'A';
51  unsigned int last = 1;
52  for (int x = 0; x < numExampleNodes; x++)
53  {
54  n = new node(nodeName);
55  nodeName[0]++;
56  n->SetLabelL(kHeuristic, 0);
57  g->AddNode(n);
58  if (x == numExampleNodes-1)
59  g->AddEdge(new edge(last, n->GetNum(), numExampleNodes-1));
60  else
61  g->AddEdge(new edge(last, n->GetNum(), 1));
62  last = n->GetNum();
63 
64  n->SetLabelF(GraphSearchConstants::kXCoordinate, -0.8+1.6*(double(x)/(numExampleNodes-1.0)));
67  }
68  return g;
69  }
70 
71  Graph *GetExpoGraph(int numExampleNodes, bool a)
72  {
73  Graph *g = new Graph();
74  char nodeName[2] = {'a', 0};
75  nodeName[0]+=numExampleNodes-1;
76  for (int x = 0; x <= numExampleNodes; x++)
77  {
78  node *n;
79  if (x == 0)
80  {
81  g->AddNode(n = new node("G"));
82  }
83  else {
84  g->AddNode(n = new node(nodeName));
85  nodeName[0]--;
86  }
87  if (x == 0 || x == 1)
88  {
89  n->SetLabelL(kHeuristic, 0);
90  }
91  else {
92  n->SetLabelL(kHeuristic, (1<<(x-1)) + 2*x - 3);
93  }
94 
95  double val = 1.5*PI*x/(numExampleNodes+1.0)-PI/4;
99  }
100 
101  g->AddEdge(new edge(1,0,(1<<(numExampleNodes-1)) + numExampleNodes - 2));
102  for (int x = 1; x <= numExampleNodes; x++)
103  {
104  for (int y = x+1; y <= numExampleNodes; y++)
105  {
106  g->AddEdge(new edge(y, x, (1<<(y-2)) + y - (1<<(x-1)) - x));
107  }
108  }
109 
110  if (!a)
111  g->GetNode(numExampleNodes)->SetLabelL(kHeuristic, 0);
112 
113  return g;
114  }
115 
116  // This graph is from Martelli, 1979
118  {
119  return GetExpoGraph(N, true);
120  }
121 
122  // This graph is from Mero, 1984
124  {
125  return GetExpoGraph(N, false);
126  }
127 
128 
129  Graph *GetWeightedInconsistency(float w, int numExampleNodes)
130  {
131  {
132  Graph *g = new Graph();
133  node *n;
134 
135  char nodeName[3] = {'t', '0', 0};
136  for (int x = 0; x < numExampleNodes; x++)
137  {
138  n = new node(nodeName);
139  nodeName[1]++;
140  n->SetLabelF(kHeuristic, numExampleNodes-x-1);
141  n->SetLabelF(GraphSearchConstants::kXCoordinate, -0.8+1.6*(double(x)/(numExampleNodes-1)));
144  g->AddNode(n);
145  if (x > 0)
146  g->AddEdge(new edge(n->GetNum()-1, n->GetNum(), 1));
147  }
148  nodeName[0] = 'b';
149  nodeName[1] = '0';
150  for (int x = 0; x < numExampleNodes; x++)
151  {
152  n = new node(nodeName);
153  nodeName[1]++;
154  n->SetLabelF(kHeuristic, numExampleNodes-x-1);
155  n->SetLabelF(GraphSearchConstants::kXCoordinate, -0.8+1.6*(double(x)/(numExampleNodes-1)));
158  g->AddNode(n);
159  g->AddEdge(new edge(n->GetNum()-numExampleNodes, n->GetNum(), (x+1.0)*(w-1)/w));
160  if (x > 0)
161  g->AddEdge(new edge(n->GetNum()-1, n->GetNum(), 1));
162  }
163  n = new node("e");
164  n->SetLabelF(kHeuristic, numExampleNodes);
165  n->SetLabelF(GraphSearchConstants::kXCoordinate, -0.8+1.6*(double(0)/(numExampleNodes-1)));
168  g->AddNode(n);
169  g->AddEdge(new edge(n->GetNum()-numExampleNodes, n->GetNum(), 1));
170 
171  n = new node("g");
172  n->SetLabelF(kHeuristic, 0);
176  g->AddNode(n);
177  g->AddEdge(new edge(n->GetNum()-1, n->GetNum(), numExampleNodes));
178 
179  return g;
180  }
181  }
182 
183 }
Graph::AddNode
int AddNode(node *)
Definition: Graph.cpp:136
node::SetLabelL
void SetLabelL(unsigned int index, long val) const
Definition: Graph.cpp:702
node::SetLabelF
void SetLabelF(unsigned int index, double val) const
Definition: Graph.cpp:687
GraphInconsistencyExamples::GetExpoGraph
Graph * GetExpoGraph(int numExampleNodes, bool a)
Definition: GraphInconsistencyInstances.cpp:71
Graph::AddEdge
void AddEdge(edge *)
Definition: Graph.cpp:170
GraphSearchConstants::kXCoordinate
@ kXCoordinate
Definition: GraphEnvironment.h:51
Graph
A generic Graph class.
Definition: Graph.h:66
Graph::GetNode
node * GetNode(unsigned long num)
Definition: Graph.cpp:152
GraphInconsistencyExamples::kHeuristic
const int kHeuristic
Definition: GraphInconsistencyInstances.h:17
GraphInconsistencyExamples::GetPolyGraph
Graph * GetPolyGraph(int numExampleNodes)
Definition: GraphInconsistencyInstances.cpp:15
PI
static const double PI
Definition: GLUtil.h:66
GraphInconsistencyExamples::GetExpoGraphA
Graph * GetExpoGraphA(int N)
Definition: GraphInconsistencyInstances.cpp:117
GraphSearchConstants::kYCoordinate
@ kYCoordinate
Definition: GraphEnvironment.h:52
node::GetNum
unsigned int GetNum() const
Definition: Graph.h:176
GraphSearchConstants::kZCoordinate
@ kZCoordinate
Definition: GraphEnvironment.h:53
GraphInconsistencyExamples::GetWeightedInconsistency
Graph * GetWeightedInconsistency(float w, int numExampleNodes)
Definition: GraphInconsistencyInstances.cpp:129
GraphInconsistencyExamples
Definition: GraphInconsistencyInstances.cpp:12
GraphInconsistencyExamples::GetExpoGraphB
Graph * GetExpoGraphB(int N)
Definition: GraphInconsistencyInstances.cpp:123
GraphInconsistencyInstances.h
node
Nodes to be stored within a Graph.
Definition: Graph.h:170
GraphEnvironment.h
edge
Edge class for connections between node in a Graph.
Definition: Graph.h:129