Skip to content

Commit

Permalink
Display depleted inventory
Browse files Browse the repository at this point in the history
  • Loading branch information
JamesBremner committed Jun 30, 2020
1 parent 8a42a48 commit 8c62101
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 10 deletions.
5 changes: 5 additions & 0 deletions src/TimberAllocation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,13 @@ int main( int argc, char* argv[] )
// cut out orders from stock by level
LevelCuts( I, levels, theInventory );

ReturnToInventory( theInventory );

// display solution
std::cout << I.textSolution();

// display depleted inventory
std::cout << theInventory.textDetails();
}
catch( std::runtime_error& e )
{
Expand Down
26 changes: 21 additions & 5 deletions src/TimberAllocation.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ class cTimber : public cSpace
return myPacked;
}

void setUsed()
void used( bool f = true )
{
myUsed = true;
}
Expand All @@ -81,13 +81,24 @@ class cTimber : public cSpace
return myUsed;
}

// set the location of the top of the highest level cut
void level( int h )
{
myLevel = h;
}
int level() const
{
return myLevel;
}

std::string myUserID;
int myCount;

private:
bool myPacked;
bool myUsed;
timber_t myStock;
bool myPacked; // true if an order that has been allocated
timber_t myStock; // if an allocated order, the stock allocated to
bool myUsed; // true if a stock that haveen used to cut orders
int myLevel; // the location of the top of the highest level cut
};

class cInventory
Expand All @@ -97,6 +108,7 @@ class cInventory
void add( timber_t t );
void expandCount();
std::string text();
std::string textDetails();

/** Sort inventory into stock, sheets and scraps
@param[in] sheetHeight maximum sheet height
Expand Down Expand Up @@ -246,6 +258,7 @@ bool CS2LNW(
cInstance& I,
cLevel& level, int h );

/// Use pack2 engine to do 2D level cutting
bool CS2Pack2(
cInstance& I,
cLevel& level, int h );
Expand All @@ -271,5 +284,8 @@ void AllocateOrder(
void CutLevel(
cInstance& I,
cLevel& level );
}

void ReturnToInventory(
cInventory& I );

}
39 changes: 34 additions & 5 deletions src/taCutter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -171,9 +171,6 @@ void LevelCuts(
// remove timbers from level that have been packed
level.removePacked();

// flag the stock has been used
level.myStock->setUsed();

// TODO: return unused remainders to inventory

if( ! allPacked )
Expand Down Expand Up @@ -369,20 +366,52 @@ void AllocateOrder(
{
order->pack( length, width, height, stock );
I.myAllocation.push_back( std::make_pair( order, stock ));
stock->used();
}
void CutLevel(
cInstance& I,
cLevel& level )
{
if( level.height() == level.myStock->myHeight )
timber_t stock = level.myStock;

stock->level( level.height() );

if( level.height() == stock->myHeight )
{
//no need for a cut, we are at the top of the stock
return;
}
I.myCut.push_back( cCut(
level.myStock,
stock,
'H',
level.height(),
level.height() ));
}

void ReturnToInventory(
cInventory& I )
{
// remove stock timbers whose complete height has been used
I.myStock.erase(
remove_if(
I.myStock.begin(),
I.myStock.end(),
[] ( timber_t t )
{
std::cout << "remove? " <<t->isUsed() <<" " <<t->level() <<" "<<t->myHeight << "\n";
return( t->isUsed() && t->level() == t->myHeight );
} ),
I.myStock.end() );

// adjust height of partially used stock
for( timber_t t : I.myStock )
{
if( ! t->isUsed() )
continue;

t->myHeight -= t->level();
t->level( 0 );
t->used( false );
}
}
}
10 changes: 10 additions & 0 deletions src/taInventory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,16 @@ std::string cInventory::text()
return ss.str();
}

std::string cInventory::textDetails()
{
std::stringstream ss;
for( timber_t t : myStock )
{
ss << "i " << t->myLength <<" "<< t->myWidth <<" "<< t->myHeight
<< " 1 " << t->myUserID << "\n";
}
return ss.str();
}
void cInventory::sortInventory( int sheetHeight, int scrapWidth )
{
// rotate, if neccesary, so L > W > H
Expand Down

0 comments on commit 8c62101

Please sign in to comment.