36 using namespace gtsam;
47 size_t maxLoopCount = 2000;
62 : dataset_(
filename), isWithAmbiguity(isWithAmbiguity) {
75 std::vector<std::pair<size_t, double>> smootherUpdateTimes;
77 std::list<double> timeList;
80 Pose2 priorPose(0, 0, 0);
81 initial_.
insert(
X(0), priorPose);
85 clock_t beforeUpdate = clock();
86 isam2_.
update(graph_, initial_);
88 clock_t afterUpdate = clock();
89 smootherUpdateTimes.push_back(
90 std::make_pair(index, afterUpdate - beforeUpdate));
98 clock_t startTime = clock();
100 std::vector<Pose2> poseArray;
101 std::pair<size_t, size_t>
keys;
103 while (dataset_.
next(&poseArray, &
keys) && index < maxLoopCount) {
106 size_t numMeasurements = poseArray.size();
109 if (isWithAmbiguity) {
111 int id = index % numMeasurements;
112 odomPose =
Pose2(poseArray[
id]);
114 odomPose = poseArray[0];
117 if (keyS == keyT - 1) {
123 int id = index % numMeasurements;
124 if (isWithAmbiguity &&
id % 2 == 0) {
129 X(keyS),
X(keyT), odomPose,
135 clock_t beforeUpdate = clock();
136 isam2_.
update(graph_, initial_);
138 clock_t afterUpdate = clock();
139 smootherUpdateTimes.push_back(
140 std::make_pair(index, afterUpdate - beforeUpdate));
146 if (index % 50 == 0 && keyS != keyT - 1) {
147 std::cout <<
"index: " << index << std::endl;
148 std::cout <<
"accTime: " << timeList.back() / CLOCKS_PER_SEC
152 if (keyS == keyT - 1) {
153 clock_t curTime = clock();
154 timeList.push_back(curTime - startTime);
157 if (timeList.size() % 100 == 0 && (keyS == keyT - 1)) {
158 std::string stepFileIdx = std::to_string(100000 + timeList.size());
160 std::ofstream stepOutfile;
161 std::string stepFileName =
"step_files/ISAM2_City10000_S" + stepFileIdx;
162 stepOutfile.open(stepFileName +
".txt");
163 for (
size_t i = 0;
i < (keyT + 1); ++
i) {
165 stepOutfile << outPose.
x() <<
" " << outPose.
y() <<
" "
166 << outPose.
theta() << std::endl;
172 clock_t endTime = clock();
173 clock_t totalTime = endTime - startTime;
174 std::cout <<
"totalTime: " << totalTime / CLOCKS_PER_SEC << std::endl;
179 std::ofstream outfileTime;
180 std::string timeFileName =
"ISAM2_City10000_time.txt";
181 outfileTime.open(timeFileName);
182 for (
auto accTime : timeList) {
183 outfileTime << accTime << std::endl;
186 std::cout <<
"Written cumulative time to: " << timeFileName <<
" file."
189 std::ofstream timingFile;
190 std::string timingFileName =
"ISAM2_City10000_timing.txt";
191 timingFile.open(timingFileName);
192 for (
size_t i = 0;
i < smootherUpdateTimes.size();
i++) {
193 auto p = smootherUpdateTimes.at(
i);
194 timingFile <<
p.first <<
", " <<
p.second / CLOCKS_PER_SEC << std::endl;
197 std::cout <<
"Wrote timing information to " << timingFileName << std::endl;
204 bool& isWithAmbiguity) {
205 for (
int i = 1;
i < argc; ++
i) {
206 std::string
arg = argv[
i];
207 if (
arg ==
"--max-loop-count" &&
i + 1 < argc) {
208 maxLoopCount = std::stoul(argv[++
i]);
209 }
else if (
arg ==
"--is-with-ambiguity" &&
i + 1 < argc) {
210 isWithAmbiguity = bool(std::stoul(argv[++
i]));
211 }
else if (
arg ==
"--help") {
212 std::cout <<
"Usage: " << argv[0] <<
" [options]\n"
214 <<
" --max-loop-count <value> Set the maximum loop "
215 "count (default: 2000)\n"
216 <<
" --is-with-ambiguity <value=0/1> Set whether to use "
217 "ambiguous measurements "
219 <<
" --help Show this help message\n";
226 int main(
int argc,
char* argv[]) {