Skip to content

Commit

Permalink
display wastage
Browse files Browse the repository at this point in the history
  • Loading branch information
JamesBremner committed Jun 30, 2020
1 parent 8c62101 commit ae326e6
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 13 deletions.
2 changes: 2 additions & 0 deletions src/TimberAllocation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ int main( int argc, char* argv[] )

// display depleted inventory
std::cout << theInventory.textDetails();

DisplayWastage( levels );
}
catch( std::runtime_error& e )
{
Expand Down
25 changes: 21 additions & 4 deletions src/TimberAllocation.h
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,13 @@ class cLevel
public:
timberv_t myOrder; // orders
timber_t myStock; // stock allocated to level
int myAreaUsed;

cLevel()
: myAreaUsed( 0 )
{

}
void removePacked(); // remove orders that have been packed
std::string text() const;
int height() const
Expand All @@ -161,6 +168,14 @@ class cLevel
{
return (int) myOrder.size();
}
void use( timber_t order )
{
myAreaUsed += order->myLength * order->myWidth;
}
int wastage() const
{
return height() * ( myStock->myLength * myStock->myWidth - myAreaUsed );
}
};

class cInstance
Expand Down Expand Up @@ -265,16 +280,16 @@ bool CS2Pack2(

/** Allocate an order
@param[in] I the instance
@param[in] stock order is allocated to
@param[in] order being allocated
@param[in] level
@param[in] order index in level
@param[[in] length position
@param[[in] width position
@param[[in] height position
*/
void AllocateOrder(
cInstance& I,
timber_t& stock,
timber_t& order,
cLevel& level,
int order,
int length, int width, int height );

/** Record the V cut for a level in the instance
Expand All @@ -288,4 +303,6 @@ void CutLevel(
void ReturnToInventory(
cInventory& I );

void DisplayWastage( std::vector<cLevel>& levels );

}
31 changes: 22 additions & 9 deletions src/taCutter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -283,9 +283,7 @@ bool CS2Pack2(
for( pack2::item_t item : E.items() )
{
if( ! item->isPacked() )
{
continue;
}

packedCount++;
if( packedCount == 1 )
Expand All @@ -302,8 +300,8 @@ bool CS2Pack2(

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

Expand Down Expand Up @@ -360,13 +358,21 @@ bool CS2Pack2(

void AllocateOrder(
cInstance& I,
timber_t& stock,
timber_t& order,
cLevel& level,
int order,
int length, int width, int height )
{
order->pack( length, width, height, stock );
I.myAllocation.push_back( std::make_pair( order, stock ));
stock->used();
// allocate order to stock
level.myOrder[ order ]->pack( length, width, height, level.myStock );

// record allocation
I.myAllocation.push_back( std::make_pair( level.myOrder[ order ], level.myStock ));

// mark stock as used
level.myStock->used();

// record how much of level used
level.use( level.myOrder[ order ] );
}
void CutLevel(
cInstance& I,
Expand Down Expand Up @@ -414,4 +420,11 @@ void ReturnToInventory(
t->used( false );
}
}
void DisplayWastage( std::vector<cLevel>& levels )
{
int wastage = 0;
for( auto l : levels )
wastage += l.wastage();
std::cout << "w " << wastage << "\n";
}
}

0 comments on commit ae326e6

Please sign in to comment.