Use smarter object function in partial arrangement with empty bed.
This commit is contained in:
parent
2813db8906
commit
869ae0247e
2 changed files with 20 additions and 8 deletions
|
@ -167,6 +167,8 @@ struct NfpPConfig {
|
|||
const ItemGroup& // remaining items
|
||||
)> before_packing;
|
||||
|
||||
std::function<void(const ItemGroup &, NfpPConfig &config)> on_preload;
|
||||
|
||||
NfpPConfig(): rotations({0.0, Pi/2.0, Pi, 3*Pi/2}),
|
||||
alignment(Alignment::CENTER), starting_point(Alignment::CENTER) {}
|
||||
};
|
||||
|
@ -577,6 +579,12 @@ public:
|
|||
Base::clearItems();
|
||||
}
|
||||
|
||||
void preload(const ItemGroup& packeditems) {
|
||||
Base::preload(packeditems);
|
||||
if (config_.on_preload)
|
||||
config_.on_preload(packeditems, config_);
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
using Shapes = TMultiShape<RawShape>;
|
||||
|
|
|
@ -109,6 +109,7 @@ void fill_config(PConf& pcfg, const ArrangeParams ¶ms) {
|
|||
|
||||
// Apply penalty to object function result. This is used only when alignment
|
||||
// after arrange is explicitly disabled (PConfig::Alignment::DONT_ALIGN)
|
||||
// Also, this will only work well for Box shaped beds.
|
||||
static double fixed_overfit(const std::tuple<double, Box>& result, const Box &binbb)
|
||||
{
|
||||
double score = std::get<0>(result);
|
||||
|
@ -348,6 +349,17 @@ public:
|
|||
|
||||
m_pconf.object_function = get_objfn();
|
||||
|
||||
m_pconf.on_preload = [this](const ItemGroup &items, PConfig &cfg) {
|
||||
if (items.empty()) return;
|
||||
|
||||
cfg.alignment = PConfig::Alignment::DONT_ALIGN;
|
||||
auto bb = sl::boundingBox(m_bin);
|
||||
auto bbcenter = bb.center();
|
||||
cfg.object_function = [this, bb, bbcenter](const Item &item) {
|
||||
return fixed_overfit(objfunc(item, bbcenter), bb);
|
||||
};
|
||||
};
|
||||
|
||||
auto on_packed = params.on_packed;
|
||||
|
||||
if (progressind || on_packed)
|
||||
|
@ -384,13 +396,6 @@ public:
|
|||
const PConfig& config() const { return m_pconf; }
|
||||
|
||||
inline void preload(std::vector<Item>& fixeditems) {
|
||||
m_pconf.alignment = PConfig::Alignment::DONT_ALIGN;
|
||||
auto bb = sl::boundingBox(m_bin);
|
||||
auto bbcenter = bb.center();
|
||||
m_pconf.object_function = [this, bb, bbcenter](const Item &item) {
|
||||
return fixed_overfit(objfunc(item, bbcenter), bb);
|
||||
};
|
||||
|
||||
// Build the rtree for queries to work
|
||||
|
||||
for(unsigned idx = 0; idx < fixeditems.size(); ++idx) {
|
||||
|
@ -398,7 +403,6 @@ public:
|
|||
itm.markAsFixedInBin(itm.binId());
|
||||
}
|
||||
|
||||
m_pck.configure(m_pconf);
|
||||
m_item_count += fixeditems.size();
|
||||
}
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue