diff --git a/CMakeLists.txt b/CMakeLists.txt index 24b0e79..d018e4b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -16,7 +16,7 @@ add_library(smmincov STATIC add_executable( espresso src/main.cpp - src/Cover.cpp src/Cover.hpp src/Cube.cpp src/Cube.hpp src/Pla.cpp src/Pla.hpp src/SMMincov.cpp) + src/Cover.cpp src/Cover.hpp src/Cube.cpp src/Cube.hpp src/Pla.cpp src/Pla.hpp src/SMMincov.cpp src/Cost.cpp src/Cost.hpp) target_link_libraries(espresso smmincov) set_property(TARGET espresso PROPERTY CXX_STANDARD 20) diff --git a/src/Cost.cpp b/src/Cost.cpp new file mode 100644 index 0000000..6e57ca5 --- /dev/null +++ b/src/Cost.cpp @@ -0,0 +1,5 @@ +// +// Created by yqszxx on 10/4/21. +// + +#include "Cost.hpp" diff --git a/src/Cost.hpp b/src/Cost.hpp new file mode 100644 index 0000000..71fa757 --- /dev/null +++ b/src/Cost.hpp @@ -0,0 +1,21 @@ +// +// Created by yqszxx on 10/4/21. +// + +#ifndef ESPRESSO_COST_HPP +#define ESPRESSO_COST_HPP + +#include + +namespace espresso { + +class Cost { +public: + size_t cubes; + size_t in; + size_t out; +}; + +} // namespace espresso + +#endif //ESPRESSO_COST_HPP diff --git a/src/Cube.cpp b/src/Cube.cpp index c28e3d3..e8e67da 100644 --- a/src/Cube.cpp +++ b/src/Cube.cpp @@ -283,3 +283,9 @@ size_t espresso::Cube::count() const { void espresso::Cube::reset() { data->reset(); } + +espresso::Cube espresso::Cube::operator~() const { + Cube r; + (*r.data) = ~(*data); + return r; +} diff --git a/src/Cube.hpp b/src/Cube.hpp index b364471..d00c064 100644 --- a/src/Cube.hpp +++ b/src/Cube.hpp @@ -30,6 +30,7 @@ class Cube { Cube operator + (const Cube& x) const; Cube& operator += (const Cube& x); Cube operator & (const Cube& x) const; + Cube operator ~ () const; bool operator <= (const Cube& x) const; // implies bool operator <=> (const Cube& x) const; // disjoint bool operator == (const Cube& x) const; diff --git a/src/Pla.cpp b/src/Pla.cpp index e6b7afa..ad4d258 100644 --- a/src/Pla.cpp +++ b/src/Pla.cpp @@ -404,3 +404,13 @@ void PLA::expand() { } } } + +Cost PLA::cost() const { + Cost cost{}; + for (auto& c: F.cubes) { + cost.in += (~((*c) + Cube::getOutputMask())).count(); + cost.out += ((*c) & Cube::getOutputMask()).count(); + cost.cubes++; + } + return cost; +} diff --git a/src/Pla.hpp b/src/Pla.hpp index a58d9b5..6b156c8 100644 --- a/src/Pla.hpp +++ b/src/Pla.hpp @@ -6,6 +6,7 @@ #define ESPRESSO_PLA_HPP #include "Cover.hpp" +#include "Cost.hpp" namespace espresso { @@ -14,6 +15,7 @@ class PLA { explicit PLA(); void dump() const; void expand(); + Cost cost() const; private: Cover F, D, R; diff --git a/src/main.cpp b/src/main.cpp index 62f97a9..81e60d6 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -7,7 +7,11 @@ int main(int, char*[]) { espresso::PLA pla; + espresso::Cost cost = pla.cost(); + std::cerr << "I:c=" << cost.cubes << ",in=" << cost.in << ",out=" << cost.out << ",total=" << cost.in + cost.out << std::endl; pla.expand(); pla.dump(); + cost = pla.cost(); + std::cerr << "O:c=" << cost.cubes << ",in=" << cost.in << ",out=" << cost.out << ",total=" << cost.in + cost.out << std::endl; return EXIT_SUCCESS; }