Skip to content

Commit

Permalink
Implement PLA.cost
Browse files Browse the repository at this point in the history
  • Loading branch information
yqszxx committed Oct 4, 2021
1 parent de95238 commit d56f47e
Show file tree
Hide file tree
Showing 8 changed files with 50 additions and 1 deletion.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
5 changes: 5 additions & 0 deletions src/Cost.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
//
// Created by yqszxx on 10/4/21.
//

#include "Cost.hpp"
21 changes: 21 additions & 0 deletions src/Cost.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
//
// Created by yqszxx on 10/4/21.
//

#ifndef ESPRESSO_COST_HPP
#define ESPRESSO_COST_HPP

#include <cstddef>

namespace espresso {

class Cost {
public:
size_t cubes;
size_t in;
size_t out;
};

} // namespace espresso

#endif //ESPRESSO_COST_HPP
6 changes: 6 additions & 0 deletions src/Cube.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
1 change: 1 addition & 0 deletions src/Cube.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
10 changes: 10 additions & 0 deletions src/Pla.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
2 changes: 2 additions & 0 deletions src/Pla.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#define ESPRESSO_PLA_HPP

#include "Cover.hpp"
#include "Cost.hpp"

namespace espresso {

Expand All @@ -14,6 +15,7 @@ class PLA {
explicit PLA();
void dump() const;
void expand();
Cost cost() const;

private:
Cover F, D, R;
Expand Down
4 changes: 4 additions & 0 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

0 comments on commit d56f47e

Please sign in to comment.