From f90dd95880036c53318eacc5c9d6ca6bb89be7d1 Mon Sep 17 00:00:00 2001 From: "luca.mazzoleni" Date: Thu, 14 May 2026 16:44:12 +0200 Subject: [PATCH] - in NestProcess creato il loop di base dello script. Mancano funzioni accessorie --- NestProcess.lua | 59 +++++++++++++++++++++++++++++++++---------------- 1 file changed, 40 insertions(+), 19 deletions(-) diff --git a/NestProcess.lua b/NestProcess.lua index 743780a..b69a184 100644 --- a/NestProcess.lua +++ b/NestProcess.lua @@ -15,6 +15,19 @@ local RawInventory = { ActiveBeams = {} } +function RawInventory:GetNewBeam( dLength) + + local NewBeam = { + dTotalLength = dLength, + dResidual = dLength, + LastOffsetX = { 0, 0, 0, 0}, + LastVtN = Vector3d( 1, 0, 0), + NestedParts = {} + } + + return NewBeam +end + function RawInventory:BuildStock() if #LEN ~= #QTY then error( 'NestProcess: invalid stock data') @@ -41,13 +54,7 @@ function RawInventory:AddActiveBeam( nStockIndex) CurrentStock.nCount = CurrentStock.nCount - 1 -- aggiungo una nuova barra attiva - local NewBeam = { - dTotalLength = CurrentStock.dLength, - dResidual = CurrentStock.dLength, - LastOffsetX = { 0, 0, 0, 0}, - LastVtN = Vector3d( 1, 0, 0), - NestedParts = {} - } + local NewBeam = self:GetNewBeam( CurrentStock.dLength) table.insert( self.ActiveBeams, NewBeam) return NewBeam @@ -140,25 +147,39 @@ RawInventory:BuildStock() -- costruzione lista pezzi template con proprietà geometriche e lista pezzi fisici da nestare BuildPartTemplatesAndJobPool() --- loop principale: scorre le barre, si già attive che a stock, e le riempie nel modo migliore possibile +-- loop principale: scorre le barre, sia già attive che a stock, e le riempie nel modo migliore possibile +-- per ogni giro sceglie la soluzione con punteggio più alto while true do local BestMove - local HighestScore = GEO.INFINITO + local dHighestScore = -GEO.INFINITO -- 1 Si provano le barre già attive - - - -- 2 Si provano le barre ancora a stock - for i = 1, #RawInventory.Stock do - if RawInventory.Stock[i].nCount > 0 then - + for i = 1, #RawInventory.ActiveBeams do + local CurrentMove = FindBestPartForBeam( RawInventory.ActiveBeams[i], JobPool) + if CurrentMove and CurrentMove.dScore > dHighestScore then + dHighestScore = CurrentMove.dScore + BestMove = CurrentMove + BestMove.nActiveBeamIndex = i end end + -- 2 Si provano le barre ancora a stock + for i = 1, #RawInventory.Stock do + local VirtualBeam = RawInventory:GetNewBeam( RawInventory.Stock[i].dLength) + if RawInventory.Stock[i].nCount > 0 then + local CurrentMove = FindBestPartForBeam( VirtualBeam, JobPool) + if CurrentMove and CurrentMove.dScore > dHighestScore then + dHighestScore = CurrentMove.dScore + BestMove = CurrentMove + BestMove.nStockIndex = i + end + end + end -- 3 Procedi con nesting - - - - + if BestMove then + CommitBestMove() + else + break + end end \ No newline at end of file