Skip to content

Commit ae326e6

Browse files
committed
display wastage
1 parent 8c62101 commit ae326e6

File tree

3 files changed

+45
-13
lines changed

3 files changed

+45
-13
lines changed

src/TimberAllocation.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ int main( int argc, char* argv[] )
4545

4646
// display depleted inventory
4747
std::cout << theInventory.textDetails();
48+
49+
DisplayWastage( levels );
4850
}
4951
catch( std::runtime_error& e )
5052
{

src/TimberAllocation.h

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,13 @@ class cLevel
151151
public:
152152
timberv_t myOrder; // orders
153153
timber_t myStock; // stock allocated to level
154+
int myAreaUsed;
155+
156+
cLevel()
157+
: myAreaUsed( 0 )
158+
{
159+
160+
}
154161
void removePacked(); // remove orders that have been packed
155162
std::string text() const;
156163
int height() const
@@ -161,6 +168,14 @@ class cLevel
161168
{
162169
return (int) myOrder.size();
163170
}
171+
void use( timber_t order )
172+
{
173+
myAreaUsed += order->myLength * order->myWidth;
174+
}
175+
int wastage() const
176+
{
177+
return height() * ( myStock->myLength * myStock->myWidth - myAreaUsed );
178+
}
164179
};
165180

166181
class cInstance
@@ -265,16 +280,16 @@ bool CS2Pack2(
265280

266281
/** Allocate an order
267282
@param[in] I the instance
268-
@param[in] stock order is allocated to
269-
@param[in] order being allocated
283+
@param[in] level
284+
@param[in] order index in level
270285
@param[[in] length position
271286
@param[[in] width position
272287
@param[[in] height position
273288
*/
274289
void AllocateOrder(
275290
cInstance& I,
276-
timber_t& stock,
277-
timber_t& order,
291+
cLevel& level,
292+
int order,
278293
int length, int width, int height );
279294

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

306+
void DisplayWastage( std::vector<cLevel>& levels );
307+
291308
}

src/taCutter.cpp

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -283,9 +283,7 @@ bool CS2Pack2(
283283
for( pack2::item_t item : E.items() )
284284
{
285285
if( ! item->isPacked() )
286-
{
287286
continue;
288-
}
289287

290288
packedCount++;
291289
if( packedCount == 1 )
@@ -302,8 +300,8 @@ bool CS2Pack2(
302300

303301
AllocateOrder(
304302
I,
305-
level.myStock,
306-
level.myOrder[ atoi( item->userID().c_str() ) ],
303+
level,
304+
atoi( item->userID().c_str() ),
307305
item->locX(), item->locY(), h );
308306
}
309307

@@ -360,13 +358,21 @@ bool CS2Pack2(
360358

361359
void AllocateOrder(
362360
cInstance& I,
363-
timber_t& stock,
364-
timber_t& order,
361+
cLevel& level,
362+
int order,
365363
int length, int width, int height )
366364
{
367-
order->pack( length, width, height, stock );
368-
I.myAllocation.push_back( std::make_pair( order, stock ));
369-
stock->used();
365+
// allocate order to stock
366+
level.myOrder[ order ]->pack( length, width, height, level.myStock );
367+
368+
// record allocation
369+
I.myAllocation.push_back( std::make_pair( level.myOrder[ order ], level.myStock ));
370+
371+
// mark stock as used
372+
level.myStock->used();
373+
374+
// record how much of level used
375+
level.use( level.myOrder[ order ] );
370376
}
371377
void CutLevel(
372378
cInstance& I,
@@ -414,4 +420,11 @@ void ReturnToInventory(
414420
t->used( false );
415421
}
416422
}
423+
void DisplayWastage( std::vector<cLevel>& levels )
424+
{
425+
int wastage = 0;
426+
for( auto l : levels )
427+
wastage += l.wastage();
428+
std::cout << "w " << wastage << "\n";
429+
}
417430
}

0 commit comments

Comments
 (0)