Skip to content

Commit

Permalink
Postpone cutting until 2D algorithm succeeds
Browse files Browse the repository at this point in the history
  • Loading branch information
JamesBremner committed Jun 29, 2020
1 parent 3e9877f commit 5d09b07
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 29 deletions.
2 changes: 1 addition & 1 deletion build/codeblocks/timberAllocation.cbp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<Option object_output="obj/Debug/" />
<Option type="1" />
<Option compiler="gcc_v83" />
<Option parameters="../data/t1.txt" />
<Option parameters="../data/timber-alloc-data.txt" />
<Compiler>
<Add option="-g" />
</Compiler>
Expand Down
3 changes: 3 additions & 0 deletions data/t2.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
i 6000 2050 1000 1 i1
i 6000 3050 1010 1 i2
d 4000 3000 1000 1 o1
18 changes: 14 additions & 4 deletions src/TimberAllocation.h
Original file line number Diff line number Diff line change
Expand Up @@ -243,11 +243,21 @@ void LevelCuts(
The wastage is likely to be enormous!
*/
bool CS2LNW(
cInstance& I,
cLevel& level, int h );
cInstance& I,
cLevel& level, int h );

bool CS2Pack2(
cInstance& I,
cLevel& level, int h );
cInstance& I,
cLevel& level, int h );

void CutOrder(
cInstance& I,
timber_t& stock,
timber_t& order,
int length, int width, int height );

void CutLevel(
cInstance& I,
cLevel& level );
}

68 changes: 44 additions & 24 deletions src/taCutter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -122,18 +122,7 @@ LevelToStock(
<< " allocated stock " << best_stock->text() << "\n";

level.myStock = best_stock;
for( timber_t o : level.myOrder )
{
I.myAllocation.push_back( std::make_pair( o, best_stock ));
}
for( int cut = level_height; cut < best_stock->myHeight; cut += level_height )
{
I.myCut.push_back( cCut(
best_stock,
'H',
cut,
cut ));
}

return true;
}

Expand Down Expand Up @@ -280,27 +269,38 @@ bool CS2Pack2(
// run the Pack2 engine
Pack( E );

std::cout << "Pack2 cutlist\n";
for( auto& c : pack2::CutList( E ) )
{
for( int v : c )
std::cout << v << ", ";
std::cout << "\n";
}

std::cout << "\nPack2 csv\n";
std::cout << pack2::CSV( E );
// std::cout << "Pack2 cutlist\n";
// for( auto& c : pack2::CutList( E ) )
// {
// for( int v : c )
// std::cout << v << ", ";
// std::cout << "\n";
// }
//
// std::cout << "\nPack2 csv\n";
// std::cout << pack2::CSV( E );

int unpackedCount = 0;
for( pack2::item_t item : E.items() )
{
if( ! item->isPacked() )
{
unpackedCount++;
if( unpackedCount == 1 )
{
CutLevel(
I,
level );
}
continue;
}
// order was cut
level.myOrder[ atoi( item->userID().c_str() ) ]->pack( item->locX(), item->locY(), h, level.myStock );
// order cut

CutOrder(
I,
level.myStock,
level.myOrder[ atoi( item->userID().c_str() ) ],
item->locX(), item->locY(), h );
}

// check for nothing packed
Expand Down Expand Up @@ -335,4 +335,24 @@ bool CS2Pack2(

return ( unpackedCount == 0 );
}

void CutOrder(
cInstance& I,
timber_t& stock,
timber_t& order,
int length, int width, int height )
{
order->pack( length, width, height, stock );
I.myAllocation.push_back( std::make_pair( order, stock ));
}
void CutLevel(
cInstance& I,
cLevel& level )
{
I.myCut.push_back( cCut(
level.myStock,
'H',
level.height(),
level.height() ));
}
}

0 comments on commit 5d09b07

Please sign in to comment.