27 out<<string(4*indent.mIndent,
' ');
32 ofstream ofile(filename.c_str());
34 throw invalid_argument(
"bool XmlWriter::writeXmlFile(...): Cannot open the output file!");
36 ofile.setf(ios::fixed, ios::floatfield);
38 if (Settings::VERBOSE && !mLines.empty())
39 cout<<
"Writing instances to xml file:"<<endl;
42 ofile<<
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>"<<endl;
43 ofile<<
"<dataset xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:noNamespaceSchemaLocation=\"dataset.xsd\">"<<endl;
44 if (!Settings::DATASET_TITLE.empty())
45 ofile<<
Indent(1)<<
"<name>"<<Settings::DATASET_TITLE<<
"</name>"<<endl;
48 writeInstanceXmlPart(ofile, line, lineId++, 1);
49 if (Settings::VERBOSE) {
50 cout<<
" 0 % ["<<setfill(
'#')<<setw(50)<<string(50*(mLines.size()-lineId)/mLines.size(),
' ')<<
"] ";
51 cout<<setprecision(2)<<fixed<<100.0*lineId/mLines.size()<<
" %"<<
'\r';
55 ofile<<
"</dataset>"<<endl;
57 if (Settings::VERBOSE && !mLines.empty())
64 out<<
Indent(length++)<<
"<instance>\n";
66 out<<
Indent(length)<<
"<name>Robotic line "<<lineId<<
"</name>\n";
68 out<<
Indent(length++)<<
"<robots>\n";
69 for (uint32_t r = 0; r < line->robots().size(); ++r)
70 writeRobotXmlPart(out, line->robots()[r], r, length);
71 out<<
Indent(--length)<<
"</robots>\n";
73 writeInterRobotOperationsXmlPart(out, line, length);
74 writeCollisionsXmlPart(out, line, length);
76 out<<
Indent(length)<<
"<production-cycle-time>"<<line->productionCycleTime()<<
"</production-cycle-time>\n";
78 out<<
Indent(--length)<<
"</instance>"<<endl;
82 out<<
Indent(length++)<<
"<robot>\n";
84 out<<
Indent(length)<<
"<name>Robot "<<robotId<<
"</name>\n";
86 out<<
Indent(length++)<<
"<activities>\n";
87 for (
Activity *a : robot->activities()) {
88 if (a->type() != MOVEMENT) {
91 writeStaticActivityXmlPart(out, sa, length);
93 throw runtime_error(
"void XmlWriter::writeRobotXmlPart(...): Invalid cast to the static activity!");
97 for (
Activity *a : robot->activities()) {
98 if (a->type() == MOVEMENT) {
101 writeDynamicActivityXmlPart(out, da, length);
103 throw runtime_error(
"void XmlWriter::writeRobotXmlPart(...): Invalid cast to the dynamic activity!");
106 out<<
Indent(--length)<<
"</activities>\n";
108 out<<
Indent(length++)<<
"<power-saving-modes>\n";
109 const vector<RobotPowerMode*>& rpm = robot->robotModes();
110 for (uint32_t p = 0; p < rpm.size(); ++p) {
111 out<<
Indent(length++)<<
"<power-mode pid=\""<<p<<
"\">\n";
112 out<<
Indent(length)<<
"<name>"<<rpm[p]->powerSaveModeName()<<
"</name>\n";
113 out<<
Indent(length)<<
"<minimal-idle-time>"<<rpm[p]->minimalDelay()<<
"</minimal-idle-time>\n";
114 if (rpm[p]->expectedInputPower() != -1.0)
115 out<<
Indent(length)<<
"<expected-input-power>"<<rpm[p]->expectedInputPower()<<
"</expected-input-power>\n";
116 out<<
Indent(--length)<<
"</power-mode>\n";
118 out<<
Indent(--length)<<
"</power-saving-modes>\n";
121 out<<
Indent(--length)<<
"</robot>\n";
125 out<<
Indent(length++)<<
"<static-activity aid=\""<<a->aid()<<
"\""<<(a->type() == WAIT ?
" last_in_cycle=\"true\"" :
"")<<
">\n";
127 out<<
Indent(length)<<
"<min-duration>"<<a->minAbsDuration()<<
"</min-duration>\n";
128 out<<
Indent(length)<<
"<max-duration>"<<a->maxAbsDuration()<<
"</max-duration>\n";
131 out<<
Indent(length++)<<
"<locations>\n";
132 for (
Location* pt : a->locations()) {
133 out<<
Indent(length++)<<
"<location lid=\""<<modeId++<<
"\">\n";
134 out<<
Indent(length)<<
"<point>"<<pt->point()<<
"</point>\n";
136 if (!pt->locationDependentPowerConsumption().empty()) {
137 out<<
Indent(length++)<<
"<location-dependent-power-consumption>\n";
139 out<<
Indent(length)<<
"<consumption pid=\""<<ld.robotModeRef()->pid()<<
"\" input_power=\""<<ld.inputPower()<<
"\" />\n";
140 out<<
Indent(--length)<<
"</location-dependent-power-consumption>\n";
143 out<<
Indent(--length)<<
"</location>\n";
145 out<<
Indent(--length)<<
"</locations>\n";
147 out<<
Indent(--length)<<
"</static-activity>\n";
151 out<<
Indent(length++)<<
"<dynamic-activity aid=\""<<a->aid()<<
"\">\n";
154 Activity *from =
nullptr, *to =
nullptr;
156 if (!a->predecessors().empty() && !a->successors().empty()) {
157 from = a->predecessors().front();
158 to = a->successors().front();
160 throw runtime_error(
"void XmlWriter::writeDynamicActivityXmlPart(...): Predecessors and successors of the activity are unset!");
163 out<<
Indent(length++)<<
"<movements from_aid=\""<<from->aid()<<
"\" to_aid=\""<<to->aid()<<
"\">\n";
164 for (
Movement* mv : a->movements()) {
165 out<<
Indent(length++)<<
"<movement mid=\""<<modeId++<<
"\">\n";
167 out<<
Indent(length)<<
"<from-point>"<<mv->from()<<
"</from-point>\n";
168 out<<
Indent(length)<<
"<to-point>"<<mv->to()<<
"</to-point>\n";
169 out<<
Indent(length)<<
"<min-duration>"<<mv->minDuration()<<
"</min-duration>\n";
170 out<<
Indent(length)<<
"<max-duration>"<<mv->maxDuration()<<
"</max-duration>\n";
172 out<<
Indent(length++)<<
"<energy-function>\n";
173 for (
const Monomial& m : mv->energyFunction())
174 out<<
Indent(length)<<
"<monomial degree=\""<<m.degree<<
"\" coeff=\""<<m.coeff<<
"\"/>\n";
175 out<<
Indent(--length)<<
"</energy-function>\n";
177 out<<
Indent(--length)<<
"</movement>\n";
179 out<<
Indent(--length)<<
"</movements>\n";
181 out<<
Indent(--length)<<
"</dynamic-activity>\n";
186 if (!line->interRobotOperations().empty()) {
187 out<<
Indent(length++)<<
"<inter-robot-operations>\n";
190 out<<
Indent(length++)<<
"<operation oid=\""<<op.oid()<<
"\">\n";
191 out<<
Indent(length)<<
"<name>"<<op.name()<<
"</name>\n";
193 out<<
Indent(length++)<<
"<time-compatibility>\n";
194 for (
const TimeLag& e : op.timeLags()) {
195 out<<
Indent(length++)<<
"<time-lag>\n";
196 out<<
Indent(length)<<
"<from-activity>"<<e.from()->aid()<<
"</from-activity>\n";
197 out<<
Indent(length)<<
"<to-activity>"<<e.to()->aid()<<
"</to-activity>\n";
198 out<<
Indent(length)<<
"<length>"<<e.length()<<
"</length>\n";
199 out<<
Indent(length)<<
"<height>"<<e.height()<<
"</height>\n";
200 out<<
Indent(--length)<<
"</time-lag>\n";
202 out<<
Indent(--length)<<
"</time-compatibility>\n";
204 if (!op.spatialCompatibility().empty()) {
205 out<<
Indent(length++)<<
"<spatial-compatibility>\n";
206 for (
const Pair& spc : op.spatialCompatibility()) {
207 out<<
Indent(length++)<<
"<compatible-pair>\n";
208 out<<
Indent(length)<<
"<location aid=\""<<spc.activity1()->aid()<<
"\" lid=\""<<spc.mode1()<<
"\" />\n";
209 out<<
Indent(length)<<
"<location aid=\""<<spc.activity2()->aid()<<
"\" lid=\""<<spc.mode2()<<
"\" />\n";
210 out<<
Indent(--length)<<
"</compatible-pair>\n";
212 out<<
Indent(--length)<<
"</spatial-compatibility>\n";
215 out<<
Indent(--length)<<
"</operation>\n";
217 out<<
Indent(--length)<<
"</inter-robot-operations>\n";
222 if (!line->collisions().empty()) {
223 out<<
Indent(length++)<<
"<collision-zones>\n";
224 for (
const Pair& c : line->collisions()) {
225 out<<
Indent(length++)<<
"<collision-pair>\n";
226 vector<pair<Activity*, uint32_t> > pairs = {{c.activity1(), c.mode1()}, {c.activity2(), c.mode2()}};
228 for (
const auto& p : pairs) {
229 if (p.first->type() == MOVEMENT)
230 out<<
Indent(length)<<
"<movement aid=\""<<p.first->aid()<<
"\" mid=\""<<p.second<<
"\" />\n";
232 out<<
Indent(length)<<
"<location aid=\""<<p.first->aid()<<
"\" lid=\""<<p.second<<
"\" />\n";
235 out<<
Indent(--length)<<
"</collision-pair>\n";
237 out<<
Indent(--length)<<
"</collision-zones>\n";
The class represents the robot movement between two coordinates.
Auxiliary class encapsulating two activities to form collision or spatial compatibility pair...
void writeRobotXmlPart(std::ostream &out, Robot *robot, const uint32_t &robotId, uint32_t length)
It writes a part of the xml file corresponding to one robot.
The base class incorporating common properties for robot operations and movements.
void writeCollisionsXmlPart(std::ostream &out, RoboticLine *line, uint32_t length)
It writes a part of the xml file corresponding to the spatial collisions.
The class specifies input power of the robot for a particular robot configuration.
Instance of the class includes all the data structures and methods related to a robot.
It primarily defines XmlWriter class for writing the generated instances to the file.
void writeDynamicActivityXmlPart(std::ostream &out, DynamicActivity *a, uint32_t length)
It writes a part of the xml file corresponding to one dynamic activity.
Collection of movements between two static activities.
void writeInstanceXmlPart(std::ostream &out, RoboticLine *line, const uint32_t &lineId, uint32_t length)
It writes a part of the xml file corresponding to one robotic cell.
void writeXmlFile(std::string filename=Settings::OUTPUT_FILE)
It transforms the instances of the robotic cells to the form of the xml file.
Collection of locations in which a robot operation can be performed.
It represents the part of energy functions, i.e. where is the duration of the movement.
It declares the namespace for program settings.
Auxiliary structure corresponding to the tabulator in an xml file.
Instance of TimeLag class defines a time relation between two different robots.
void writeInterRobotOperationsXmlPart(std::ostream &out, RoboticLine *line, uint32_t length)
It writes a part of the xml file corresponding to the inter-robot operations.
The inter-robot operation corresponding to the workpiece/weldment handling.
std::ostream & operator<<(std::ostream &out, const Interval< T > &t)
Overloading of the output operator for the Interval class.
It represents the location of robotic work.
The robotic cell corresponds to an instance of this class.
void writeStaticActivityXmlPart(std::ostream &out, StaticActivity *a, uint32_t length)
It writes a part of the xml file corresponding to one static activity.