30 #include <boost/algorithm/string/classification.hpp>
31 #include <boost/algorithm/string/split.hpp>
38 using namespace gtsam;
49 size_t maxLoopCount = 2000;
64 : dataset_(
filename), isWithAmbiguity(isWithAmbiguity) {
77 std::vector<std::pair<size_t, double>> smootherUpdateTimes;
79 std::list<double> timeList;
82 Pose2 priorPose(0, 0, 0);
83 initial_.
insert(
X(0), priorPose);
87 clock_t beforeUpdate = clock();
88 isam2_.
update(graph_, initial_);
90 clock_t afterUpdate = clock();
91 smootherUpdateTimes.push_back(
92 std::make_pair(index, afterUpdate - beforeUpdate));
100 clock_t startTime = clock();
102 std::vector<Pose2> poseArray;
103 std::pair<size_t, size_t>
keys;
105 while (dataset_.
next(&poseArray, &
keys) && index < maxLoopCount) {
108 size_t numMeasurements = poseArray.size();
111 if (isWithAmbiguity) {
113 int id = index % numMeasurements;
114 odomPose =
Pose2(poseArray[
id]);
116 odomPose = poseArray[0];
119 if (keyS == keyT - 1) {
125 int id = index % numMeasurements;
126 if (isWithAmbiguity &&
id % 2 == 0) {
131 X(keyS),
X(keyT), odomPose,
137 clock_t beforeUpdate = clock();
138 isam2_.
update(graph_, initial_);
140 clock_t afterUpdate = clock();
141 smootherUpdateTimes.push_back(
142 std::make_pair(index, afterUpdate - beforeUpdate));
148 if (index % 50 == 0 && keyS != keyT - 1) {
149 std::cout <<
"index: " << index << std::endl;
150 std::cout <<
"accTime: " << timeList.back() / CLOCKS_PER_SEC
154 if (keyS == keyT - 1) {
155 clock_t curTime = clock();
156 timeList.push_back(curTime - startTime);
159 if (timeList.size() % 100 == 0 && (keyS == keyT - 1)) {
160 std::string stepFileIdx = std::to_string(100000 + timeList.size());
162 std::ofstream stepOutfile;
163 std::string stepFileName =
"step_files/ISAM2_City10000_S" + stepFileIdx;
164 stepOutfile.open(stepFileName +
".txt");
165 for (
size_t i = 0;
i < (keyT + 1); ++
i) {
167 stepOutfile << outPose.
x() <<
" " << outPose.
y() <<
" "
168 << outPose.
theta() << std::endl;
174 clock_t endTime = clock();
175 clock_t totalTime = endTime - startTime;
176 std::cout <<
"totalTime: " << totalTime / CLOCKS_PER_SEC << std::endl;
181 std::ofstream outfileTime;
182 std::string timeFileName =
"ISAM2_City10000_time.txt";
183 outfileTime.open(timeFileName);
184 for (
auto accTime : timeList) {
185 outfileTime << accTime << std::endl;
188 std::cout <<
"Written cumulative time to: " << timeFileName <<
" file."
191 std::ofstream timingFile;
192 std::string timingFileName =
"ISAM2_City10000_timing.txt";
193 timingFile.open(timingFileName);
194 for (
size_t i = 0;
i < smootherUpdateTimes.size();
i++) {
195 auto p = smootherUpdateTimes.at(
i);
196 timingFile <<
p.first <<
", " <<
p.second / CLOCKS_PER_SEC << std::endl;
199 std::cout <<
"Wrote timing information to " << timingFileName << std::endl;
206 bool& isWithAmbiguity) {
207 for (
int i = 1;
i < argc; ++
i) {
208 std::string
arg = argv[
i];
209 if (
arg ==
"--max-loop-count" &&
i + 1 < argc) {
210 maxLoopCount = std::stoul(argv[++
i]);
211 }
else if (
arg ==
"--is-with-ambiguity" &&
i + 1 < argc) {
212 isWithAmbiguity = bool(std::stoul(argv[++
i]));
213 }
else if (
arg ==
"--help") {
214 std::cout <<
"Usage: " << argv[0] <<
" [options]\n"
216 <<
" --max-loop-count <value> Set the maximum loop "
217 "count (default: 2000)\n"
218 <<
" --is-with-ambiguity <value=0/1> Set whether to use "
219 "ambiguous measurements "
221 <<
" --help Show this help message\n";
228 int main(
int argc,
char* argv[]) {