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::list<double> timeList;
80 Pose2 priorPose(0, 0, 0);
81 initial_.
insert(
X(0), priorPose);
85 isam2_.
update(graph_, initial_);
93 clock_t startTime = clock();
95 std::vector<Pose2> poseArray;
96 std::pair<size_t, size_t>
keys;
98 while (dataset_.
next(&poseArray, &
keys) && index < maxLoopCount) {
101 size_t numMeasurements = poseArray.size();
104 if (isWithAmbiguity) {
106 int id = index % numMeasurements;
107 odomPose =
Pose2(poseArray[
id]);
109 odomPose = poseArray[0];
112 if (keyS == keyT - 1) {
118 int id = index % numMeasurements;
119 if (isWithAmbiguity &&
id % 2 == 0) {
124 X(keyS),
X(keyT), odomPose,
130 isam2_.
update(graph_, initial_);
136 if (index % 50 == 0 && keyS != keyT - 1) {
137 std::cout <<
"index: " << index << std::endl;
138 std::cout <<
"accTime: " << timeList.back() / CLOCKS_PER_SEC
142 if (keyS == keyT - 1) {
143 clock_t curTime = clock();
144 timeList.push_back(curTime - startTime);
147 if (timeList.size() % 100 == 0 && (keyS == keyT - 1)) {
148 std::string stepFileIdx = std::to_string(100000 + timeList.size());
150 std::ofstream stepOutfile;
151 std::string stepFileName =
"step_files/ISAM2_City10000_S" + stepFileIdx;
152 stepOutfile.open(stepFileName +
".txt");
153 for (
size_t i = 0;
i < (keyT + 1); ++
i) {
155 stepOutfile << outPose.
x() <<
" " << outPose.
y() <<
" "
156 << outPose.
theta() << std::endl;
162 clock_t endTime = clock();
163 clock_t totalTime = endTime - startTime;
164 std::cout <<
"totalTime: " << totalTime / CLOCKS_PER_SEC << std::endl;
169 std::ofstream outfileTime;
170 std::string timeFileName =
"ISAM2_City10000_time.txt";
171 outfileTime.open(timeFileName);
172 for (
auto accTime : timeList) {
173 outfileTime << accTime << std::endl;
176 std::cout <<
"Written cumulative time to: " << timeFileName <<
" file."
184 bool& isWithAmbiguity) {
185 for (
int i = 1;
i < argc; ++
i) {
186 std::string
arg = argv[
i];
187 if (
arg ==
"--max-loop-count" &&
i + 1 < argc) {
188 maxLoopCount = std::stoul(argv[++
i]);
189 }
else if (
arg ==
"--is-with-ambiguity" &&
i + 1 < argc) {
190 isWithAmbiguity = bool(std::stoul(argv[++
i]));
191 }
else if (
arg ==
"--help") {
192 std::cout <<
"Usage: " << argv[0] <<
" [options]\n"
194 <<
" --max-loop-count <value> Set the maximum loop "
195 "count (default: 2000)\n"
196 <<
" --is-with-ambiguity <value=0/1> Set whether to use "
197 "ambiguous measurements "
199 <<
" --help Show this help message\n";
206 int main(
int argc,
char* argv[]) {