@@ -272,3 +272,109 @@ std::ostream& Instance::format(
272272
273273 return os;
274274}
275+
276+ void Instance::write (
277+ const std::string& instance_path) const
278+ {
279+ // Export items.
280+ std::string items_path = instance_path + " _items.csv" ;
281+ std::ofstream f_items (items_path);
282+ if (!f_items.good ()) {
283+ throw std::runtime_error (
284+ " Unable to open file \" " + items_path + " \" ." );
285+ }
286+ f_items <<
287+ " ID,"
288+ " WIDTH,"
289+ " HEIGHT,"
290+ " PROFIT,"
291+ " COPIES,"
292+ " ORIENTED,"
293+ " GROUP_ID" << std::endl;
294+ for (ItemTypeId item_type_id = 0 ;
295+ item_type_id < number_of_item_types ();
296+ ++item_type_id) {
297+ const ItemType& item_type = this ->item_type (item_type_id);
298+ f_items
299+ << item_type_id << " ,"
300+ << item_type.rect .x << " ,"
301+ << item_type.rect .y << " ,"
302+ << item_type.profit << " ,"
303+ << item_type.copies << " ,"
304+ << item_type.oriented << " ,"
305+ << item_type.group_id << std::endl;
306+ }
307+
308+ // Export bins.
309+ std::string bins_path = instance_path + " _bins.csv" ;
310+ std::ofstream f_bins (bins_path);
311+ if (!f_bins.good ()) {
312+ throw std::runtime_error (
313+ " Unable to open file \" " + bins_path + " \" ." );
314+ }
315+ f_bins <<
316+ " ID,"
317+ " WIDTH,"
318+ " HEIGHT,"
319+ " COST,"
320+ " COPIES,"
321+ " COPIES_MIN" << std::endl;
322+ for (BinTypeId bin_type_id = 0 ;
323+ bin_type_id < number_of_bin_types ();
324+ ++bin_type_id) {
325+ const BinType& bin_type = this ->bin_type (bin_type_id);
326+ f_bins
327+ << bin_type_id << " ,"
328+ << bin_type.rect .x << " ,"
329+ << bin_type.rect .y << " ,"
330+ << bin_type.cost << " ,"
331+ << bin_type.copies << " ,"
332+ << bin_type.copies_min << std::endl;
333+ }
334+
335+ // Export defects.
336+ if (number_of_defects () > 0 ) {
337+ std::string defects_path = instance_path + " _defects.csv" ;
338+ std::ofstream f_defects (defects_path);
339+ if (number_of_defects () > 0 && !f_defects.good ()) {
340+ throw std::runtime_error (
341+ " Unable to open file \" " + defects_path + " \" ." );
342+ }
343+ f_defects <<
344+ " ID,"
345+ " BIN,"
346+ " X,"
347+ " Y,"
348+ " WIDTH,"
349+ " HEIGHT" << std::endl;
350+ for (BinTypeId bin_type_id = 0 ;
351+ bin_type_id < number_of_bin_types ();
352+ ++bin_type_id) {
353+ const BinType& bin_type = this ->bin_type (bin_type_id);
354+ for (DefectId defect_id = 0 ;
355+ defect_id < (DefectId)bin_type.defects .size ();
356+ ++defect_id) {
357+ const Defect& defect = bin_type.defects [defect_id];
358+ f_defects
359+ << defect_id << " ,"
360+ << bin_type_id << " ,"
361+ << defect.pos .x << " ,"
362+ << defect.pos .y << " ,"
363+ << defect.rect .x << " ,"
364+ << defect.rect .y << std::endl;
365+ }
366+ }
367+ }
368+
369+ // Export parameters.
370+ std::string parameters_path = instance_path + " _parameters.csv" ;
371+ std::ofstream f_parameters (parameters_path);
372+ if (!f_parameters.good ()) {
373+ throw std::runtime_error (
374+ " Unable to open file \" " + parameters_path + " \" ." );
375+ }
376+ f_parameters << " NAME,VALUE" << std::endl
377+ << " objective," << objective () << std::endl
378+ << " unloading_constraint" << unloading_constraint () << std::endl;
379+
380+ }
0 commit comments