-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add initial implementation of LExpDTO, MDLExpDTO, and MapDTO with the…
…ir converters.
- Loading branch information
Lucio Trincheri
committed
Dec 17, 2024
1 parent
eac64ec
commit 6692684
Showing
13 changed files
with
655 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
/******************************************************************************* | ||
This file is part of Set--Based Graph Library. | ||
SBG Library is free software: you can redistribute it and/or modify | ||
it under the terms of the GNU General Public License as published by | ||
the Free Software Foundation, either version 3 of the License, or | ||
(at your option) any later version. | ||
SBG Library is distributed in the hope that it will be useful, | ||
but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
GNU General Public License for more details. | ||
You should have received a copy of the GNU General Public License | ||
along with SBG Library. If not, see <http://www.gnu.org/licenses/>. | ||
******************************************************************************/ | ||
|
||
#include "sbg/dto/converters/lexp_dto_converter.hpp" | ||
|
||
namespace SBG { | ||
|
||
namespace API { | ||
SBG::LIB::LExp LExpDTOConverter::convertToLExp(const LExpDTO& dto) { | ||
return SBG::LIB::LExp(dto.slope_, dto.offset_); | ||
} | ||
|
||
} // namespace API | ||
|
||
} // namespace SBG |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
/** @file lexp_dto_converter.hpp | ||
@brief <b> LExpDTOConverter implementation</b> | ||
The LExpDTOConverter is used to convert a LExpDTO to | ||
the corresponding linear expression representation. | ||
Currently, it can convert to SBG::LIB::LExp, | ||
but more conversions can be added in the future. | ||
<hr> | ||
This file is part of Set--Based Graph Library. | ||
SBG Library is free software: you can redistribute it and/or modify | ||
it under the terms of the GNU General Public License as published by | ||
the Free Software Foundation, either version 3 of the License, or | ||
(at your option) any later version. | ||
SBG Library is distributed in the hope that it will be useful, | ||
but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
GNU General Public License for more details. | ||
You should have received a copy of the GNU General Public License | ||
along with SBG Library. If not, see <http://www.gnu.org/licenses/>. | ||
******************************************************************************/ | ||
|
||
#ifndef SBG_DTO_LEXP_CONVERTER_HPP | ||
#define SBG_DTO_LEXP_CONVERTER_HPP | ||
|
||
#include "sbg/dto/lexp_dto.hpp" | ||
#include "sbg/lexp.hpp" | ||
|
||
namespace SBG { | ||
|
||
namespace API { | ||
|
||
class LExpDTOConverter { | ||
public: | ||
/** | ||
* @brief Converts a LExpDTO object to an actual linear | ||
* expression implementation (e.g., SBG::LIB::LExp). | ||
* | ||
* @param dto: The LExpDTO object to convert. | ||
* @return SBG::LIB::LExp: The converted linear expression object. | ||
*/ | ||
static SBG::LIB::LExp convertToLExp(const LExpDTO& dto); | ||
}; | ||
|
||
} // namespace API | ||
|
||
} // namespace SBG | ||
|
||
#endif // SBG_DTO_LEXP_CONVERTER_HPP |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
/******************************************************************************* | ||
This file is part of Set--Based Graph Library. | ||
SBG Library is free software: you can redistribute it and/or modify | ||
it under the terms of the GNU General Public License as published by | ||
the Free Software Foundation, either version 3 of the License, or | ||
(at your option) any later version. | ||
SBG Library is distributed in the hope that it will be useful, | ||
but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
GNU General Public License for more details. | ||
You should have received a copy of the GNU General Public License | ||
along with SBG Library. If not, see <http://www.gnu.org/licenses/>. | ||
******************************************************************************/ | ||
|
||
#include "sbg/dto/converters/map_dto_converter.hpp" | ||
#include "sbg/dto/converters/pw_mdinter_dto_converter.hpp" | ||
#include "sbg/dto/converters/multidim_lexp_dto_converter.hpp" | ||
|
||
namespace SBG { | ||
|
||
namespace API { | ||
SBG::LIB::BaseMap SBGMapDTOConverter::convertToBaseMap(const MapDTO& dto) { | ||
return SBG::LIB::BaseMap(SetDTOConverter::convertToUnordSet(dto.dom_), ExpDTOConverter::convertToExp(dto.exp_)); | ||
} | ||
|
||
SBG::LIB::CanonMap SBGMapDTOConverter::convertToCanonMap(const MapDTO& dto) { | ||
return SBG::LIB::CanonMap(SetDTOConverter::convertToOrdSet(dto.dom_), ExpDTOConverter::convertToExp(dto.exp_)); | ||
} | ||
|
||
} // namespace API | ||
|
||
} // namespace SBG |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
/** @file map_dto_converter.hpp | ||
@brief <b> SBGMapDTOConverter implementation</b> | ||
The SBGMapDTOConverter is used to convert a SBGMapDTO (MapDTO) | ||
to the corresponding SBG map representation. | ||
Currently, it can convert to SBG::LIB::SBGMap<UnordSet> (BaseMap) and | ||
SBG::LIB::SBGMap<OrdSet> (CanonMap), but more conversions can be added. | ||
<hr> | ||
This file is part of Set--Based Graph Library. | ||
SBG Library is free software: you can redistribute it and/or modify | ||
it under the terms of the GNU General Public License as published by | ||
the Free Software Foundation, either version 3 of the License, or | ||
(at your option) any later version. | ||
SBG Library is distributed in the hope that it will be useful, | ||
but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
GNU General Public License for more details. | ||
You should have received a copy of the GNU General Public License | ||
along with SBG Library. If not, see <http://www.gnu.org/licenses/>. | ||
******************************************************************************/ | ||
|
||
#ifndef SBG_DTO_MAP_CONVERTER_HPP | ||
#define SBG_DTO_MAP_CONVERTER_HPP | ||
|
||
#include "sbg/dto/map_dto.hpp" | ||
#include "sbg/map.hpp" | ||
|
||
namespace SBG { | ||
|
||
namespace API { | ||
|
||
class SBGMapDTOConverter { | ||
public: | ||
/** | ||
* @brief Converts a MapDTO object to an actual SBG map implementation | ||
* (e.g., SBG::LIB::BaseMap / SBG::LIB::CanonMap). | ||
* | ||
* @param dto: The MapDTO object to convert. | ||
* @return SBG::LIB::BaseMap/CanonMap: The converted SBG map object. | ||
*/ | ||
static SBG::LIB::BaseMap convertToBaseMap(const MapDTO& dto); | ||
static SBG::LIB::CanonMap convertToCanonMap(const MapDTO& dto); | ||
}; | ||
|
||
typedef SBGMapDTOConverter MapDTOConverter; | ||
|
||
} // namespace API | ||
|
||
} // namespace SBG | ||
|
||
#endif // SBG_DTO_MAP_CONVERTER_HPP |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
/******************************************************************************* | ||
This file is part of Set--Based Graph Library. | ||
SBG Library is free software: you can redistribute it and/or modify | ||
it under the terms of the GNU General Public License as published by | ||
the Free Software Foundation, either version 3 of the License, or | ||
(at your option) any later version. | ||
SBG Library is distributed in the hope that it will be useful, | ||
but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
GNU General Public License for more details. | ||
You should have received a copy of the GNU General Public License | ||
along with SBG Library. If not, see <http://www.gnu.org/licenses/>. | ||
******************************************************************************/ | ||
|
||
#include "sbg/dto/converters/multidim_lexp_dto_converter.hpp" | ||
#include "sbg/dto/converters/lexp_dto_converter.hpp" | ||
|
||
namespace SBG { | ||
|
||
namespace API { | ||
SBG::LIB::Exp MDLExpDTOConverter::convertToExp(const ExpDTO& dto) { | ||
SBG::LIB::Exp exp; | ||
for (const LExpDTO& lexp_dto : dto.exps_) { | ||
exp.emplaceBack(LExpDTOConverter::convertToLExp(lexp_dto)); | ||
} | ||
|
||
return exp; | ||
} | ||
|
||
} // namespace API | ||
|
||
} // namespace SBG |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
/** @file multidim_lexp_dto_converter.hpp | ||
@brief <b> MDLExpDTOConverter implementation</b> | ||
The MDLExpDTOConverter is used to convert a MDLExpDTO (ExpDTO) to the | ||
corresponding multi-dimensional linear expression representation. | ||
Currently, it can convert to SBG::LIB::MDLExp (Exp), | ||
but more conversions can be added in the future. | ||
<hr> | ||
This file is part of Set--Based Graph Library. | ||
SBG Library is free software: you can redistribute it and/or modify | ||
it under the terms of the GNU General Public License as published by | ||
the Free Software Foundation, either version 3 of the License, or | ||
(at your option) any later version. | ||
SBG Library is distributed in the hope that it will be useful, | ||
but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
GNU General Public License for more details. | ||
You should have received a copy of the GNU General Public License | ||
along with SBG Library. If not, see <http://www.gnu.org/licenses/>. | ||
******************************************************************************/ | ||
|
||
#ifndef SBG_DTO_MDLEXP_CONVERTER_HPP | ||
#define SBG_DTO_MDLEXP_CONVERTER_HPP | ||
|
||
#include "sbg/dto/multidim_lexp_dto.hpp" | ||
#include "sbg/multidim_lexp.hpp" | ||
|
||
namespace SBG { | ||
|
||
namespace API { | ||
|
||
class MDLExpDTOConverter { | ||
public: | ||
/** | ||
* @brief Converts a ExpDTO object to an actual multi-dimensional | ||
* linear expression implementation (e.g., SBG::LIB::Exp). | ||
* | ||
* @param dto: The ExpDTO object to convert. | ||
* @return SBG::LIB::Exp: The converted multi-dimensional linear expression object. | ||
*/ | ||
static SBG::LIB::Exp convertToExp(const ExpDTO& dto); | ||
}; | ||
|
||
typedef MDLExpDTOConverter ExpDTOConverter; | ||
|
||
} // namespace API | ||
|
||
} // namespace SBG | ||
|
||
#endif // SBG_DTO_MDLEXP_CONVERTER_HPP |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
/******************************************************************************* | ||
This file is part of Set--Based Graph Library. | ||
SBG Library is free software: you can redistribute it and/or modify | ||
it under the terms of the GNU General Public License as published by | ||
the Free Software Foundation, either version 3 of the License, or | ||
(at your option) any later version. | ||
SBG Library is distributed in the hope that it will be useful, | ||
but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
GNU General Public License for more details. | ||
You should have received a copy of the GNU General Public License | ||
along with SBG Library. If not, see <http://www.gnu.org/licenses/>. | ||
******************************************************************************/ | ||
|
||
#include "sbg/dto/lexp_dto.hpp" | ||
|
||
namespace SBG { | ||
|
||
namespace API { | ||
|
||
LExpDTO::LExpDTO() : slope_(1), offset_(0) {} | ||
LExpDTO::LExpDTO(RAT slope, RAT offset) : slope_(slope), offset_(offset) {} | ||
|
||
member_imp(LExpDTO, RAT, slope); | ||
member_imp(LExpDTO, RAT, offset); | ||
|
||
std::ostream &operator<<(std::ostream &out, const LExpDTO &le) | ||
{ | ||
RAT slo = le.slope_, off = le.offset_; | ||
|
||
if (slo == 0) { | ||
out << off; | ||
return out; | ||
} | ||
|
||
if (slo == 1) { | ||
out << "x"; | ||
} else { | ||
if (slo.numerator() != 1) | ||
out << slo.numerator(); | ||
|
||
if (slo.denominator() != 1) | ||
out << "x/" << slo.denominator(); | ||
|
||
else | ||
out << "x"; | ||
} | ||
|
||
if (off != 0) { | ||
out << "+" << off; | ||
} | ||
|
||
return out; | ||
} | ||
|
||
} // namespace API | ||
|
||
} // namespace SBG |
Oops, something went wrong.