process_constraints.py
Go to the documentation of this file.
1 import math
2 import sys
3 import matplotlib.pyplot as plt
4 import random
5 
6 '''
7 Purpose: This is a simple graphing tool to find the relationship between number of nodes
8  and number of constraints over time.
9 
10 To use: add the following code to publishGraph and disable the optimizer printouts
11 
12  std::map<karto::Name, std::vector<karto::Vertex<karto::LocalizedRangeScan>*> > vertices = mapper_->GetGraph()->GetVertices();
13  std::vector<karto::Vertex<karto::LocalizedRangeScan>*>::const_iterator it;
14  std::map<int, int> vertex_ctr;
15  for (it = vertices[mapper_->GetMapperSensorManager()->GetSensorNames()[0]].begin(); it != vertices[mapper_->GetMapperSensorManager()->GetSensorNames()[0]].end(); ++it)
16  {
17  int num = (*it)->GetEdges().size();
18  if (vertex_ctr.find(num) == vertex_ctr.end())
19  {
20  vertex_ctr[num] = 1;
21  }
22  vertex_ctr[num]++;
23  }
24 
25  std::cout << "UpdateMap: Vertex count: " << std::endl;
26  std::map<int, int>::const_iterator it2;
27  for (it2 = vertex_ctr.begin(); it2 != vertex_ctr.end(); ++it2)
28  {
29  std::cout << it2->first << " constraints are in " << it2->second << " vertexes" << std::endl;
30  }
31  std::cout << std::endl;
32 '''
33 
34 def readFileToList(filename):
35  with open(filename) as fp:
36  line = fp.readline()
37  lines = []
38  lines.append(line)
39  while line:
40  line = fp.readline()
41  lines.append(line)
42  return lines
43 
44 def getSingleSets(lines):
45  measurements = []
46  measurement = []
47  for line in lines:
48  if line == "\n":
49  continue
50  if "UpdateMap: Vertex count:" in line:
51  measurements.append(measurement)
52  measurement = []
53  measurement.append(line)
54  return measurements[1:]
55 
56 def processForData(measurements):
57  measurements_out = []
58  measurement_out = []
59  for measurement in measurements:
60  for m in measurement:
61  txt = m.split(" ")
62  nums = [r for r in txt if r.isdigit()]
63  if not nums:
64  continue
65  measurement_out.append(nums)
66  measurements_out.append(measurement_out)
67  measurement_out = []
68  return measurements_out
69 
70 def plotData(data):
71  #plot lines
72 
73  # give us the number of lines to create and unque items
74  max_size = 0
75  keys = []
76  for d in data:
77  for m in d:
78  if m[0] not in keys:
79  keys.append(m[0])
80 
81  data_len = len(data)
82 
83  dat = {}
84  for k in keys:
85  dat[k] = []
86 
87  for d in data:
88  local_keys = []
89  for pt in d:
90  local_keys.append(pt[0])
91  dat[pt[0]].append(int(pt[1]))
92  for k in keys:
93  if k not in local_keys:
94  dat[k].append(0)
95 
96  total_nodes = []
97  for d in data:
98  summ = 0
99  for pt in d:
100  summ = summ + int(pt[1])
101  total_nodes.append(summ)
102 
103  for k in keys:
104  plt.plot( [10*i for i in range(0, len(dat[k]))], dat[k], marker='o', color=[random.random(),random.random(),random.random()], linewidth=2, label=k+' Constraints')
105 
106  plt.plot( [10*i for i in range(0, len(dat[k]))], total_nodes, marker='o', color=[random.random(),random.random(),random.random()], linewidth=2, label='Total Num. Nodes')
107  plt.legend()
108  plt.xlabel("time (s)")
109  plt.ylabel("Node count")
110  #plt.yscale("log")
111  plt.show()
112 
113 if __name__ == "__main__":
114  filename = sys.argv[1]
115  print ("reading file: " + filename)
116  listOfContents = readFileToList(filename)
117  listOfListOfMeasurements = getSingleSets(listOfContents)
118  data = processForData(listOfListOfMeasurements)
119  plotData(data)
def processForData(measurements)
def readFileToList(filename)


slam_toolbox
Author(s): Steve Macenski
autogenerated on Mon Feb 28 2022 23:46:49