How to use it
Prerequisite: check our VB 2005 sample to see the components and their placement
Step 1. Set pieces to be cut (also called parts or DEMAND pieces).
Optimization2DX1.NumberOfDemandPieces = 14
Optimization2DX1.SetDemandPiece(0, 60, 40, 1, 0, 0)
Optimization2DX1.SetDemandPiece(1,
60, 40, 1, 1, 0)
Optimization2DX1.SetDemandPiece(2,
48, 40, 1, 2, 0)
Optimization2DX1.SetDemandPiece(3,
60, 53, 1, 3, 0)
Optimization2DX1.SetDemandPiece(4,
45, 45, 1, 4, 0)
Optimization2DX1.SetDemandPiece(5,
50, 80, 1, 5, 0)
Optimization2DX1.SetDemandPiece(6,
45, 75, 1, 6, 0)
Optimization2DX1.SetDemandPiece(7,
100, 100, 1, 7, 0)
Optimization2DX1.SetDemandPiece(8,
100, 100, 1, 8, 0)
Optimization2DX1.SetDemandPiece(9,
90, 90, 1, 9, 0)
Optimization2DX1.SetDemandPiece(10,
90, 90, 1, 10, 0)
Optimization2DX1.SetDemandPiece(11,
90, 90, 1, 11, 0)
Optimization2DX1.SetDemandPiece(12,
110, 110, 1, 12, 0)
Optimization2DX1.SetDemandPiece(13,
110, 110, 1, 13, 0)
Step 2. Set the sheets to cut from (also called stock or REPOSITORY pieces).
Optimization2DX1.NumberOfRepositoryPieces = 3
Optimization2DX1.SetRepositoryPiece(0, 300, 200, 0, 0, 0, 0, 0, 0, 0)
Optimization2DX1.SetRepositoryPiece(0, 200, 200, 0, 0, 0, 0, 1, 0, 0)
Optimization2DX1.SetRepositoryPiece(0, 300, 250, 0, 0, 0, 0, 2, 0, 0)
Step 3. Set other parameters.
Optimization2DX1.BladeWidth = 0
Optimization2DX1.OptimizationLevel = 50
Optimization2DX1.RandomSeed = 1
Step 4. Start the optimization process.
Optimization2DX1.StartGuillotine()
Step 5. Use the OnFinish event to extract the results of optimization.
' this example displays only the first sheet.
' if you want to obtain information about all
sheets just iterate through all of them
' sheets are indexed from 0 to
TotalNumberOfUtilizedRepositoryPieces
' usually the first parameter of the methods is the sheet index
Dim SheetIndex As
Long
SheetIndex = 0 ' this is the first
sheet
Dim bm As Bitmap =
New Bitmap(Picture1.Width, Picture1.Height)
Dim g As Graphics =
Graphics.FromImage(bm)
Dim surf_covered As
Double
Optimization2DX1.SurfaceCovered(SheetIndex,
surf_covered, rep_Index, rep_ID)
tbUtilizedSurface.Text =
CStr(surf_covered)
g.Clear(Color.White)
g.DrawRectangle(myPen, 0, 0, 300,
200)' draw the repository piece
Optimization2DX1.NumberOfCuttings(SheetIndex,
NoCuttings, rep_Index, rep_ID)
For i = 0 To NoCuttings
- 1
Optimization2DX1.GetCut(SheetIndex, i, tx, ty,
bx, by, thick, rep_Index, rep_ID)
g.DrawLine(myPen, tx, ty, bx, by)
Next i
Optimization2DX1.NumberOfUtilizedDemandPieces(SheetIndex,
NoPieces, rep_Index, rep_ID)
For i = 0 To NoPieces -
1
Optimization2DX1.GetUtilizedDemandPiece(SheetIndex,
i, tx, ty, bx, by, rotated, rep_Index, dem_Index, rep_ID, dem_ID)
text_size = g.MeasureString(CStr(System.Math.Abs(bx - tx)) & "x" &
CStr(System.Math.Abs(by - ty)), Font)
g.DrawString(CStr(System.Math.Abs(bx - tx)) & "x" &
CStr(System.Math.Abs(by - ty)), Font, Brushes.Black, (bx + tx) / 2 -
text_size.Width / 2, (by + ty) / 2 - text_size.Height / 2)
Next i
Optimization2DX1.NumberOfWastePieces(SheetIndex,
NoWastes, rep_Index, rep_ID)
For i = 0 To NoWastes -
1
Optimization2DX1.GetWastePiece(SheetIndex,
i, tx, ty, bx, by, rep_Index, rep_ID)
text_size = g.MeasureString("w", Font)
g.DrawString("w", Font, Brushes.Black, (bx + tx) / 2 - text_size.Width /
2, (by + ty) / 2 - text_size.Height / 2)' draw some text in the center
of the waste
Next i
Picture1.Image = bm
Prerequisite: check our Delphi 7/ 2007 sample to see the components and their placement
Step 1. Set pieces to be cut (also called parts or DEMAND pieces).
Optimization2DX1.NumberOfDemandPieces
:= 14;
Optimization2DX1.SetDemandPiece(0,
60, 40, 1, 0, 0);
Optimization2DX1.SetDemandPiece(1,
60, 40, 1, 1, 0);
Optimization2DX1.SetDemandPiece(2,
48, 40, 1, 2, 0);
Optimization2DX1.SetDemandPiece(3,
60, 53, 1, 3, 0);
Optimization2DX1.SetDemandPiece(4,
45, 45, 1, 4, 0);
Optimization2DX1.SetDemandPiece(5,
50, 80, 1, 5, 0);
Optimization2DX1.SetDemandPiece(6,
45, 75, 1, 6, 0);
Optimization2DX1.SetDemandPiece(7,
100, 100, 1, 7, 0);
Optimization2DX1.SetDemandPiece(8,
100, 100, 1, 8, 0);
Optimization2DX1.SetDemandPiece(9,
90, 90, 1, 9, 0);
Optimization2DX1.SetDemandPiece(10,
90, 90, 1, 10, 0);
Optimization2DX1.SetDemandPiece(11,
90, 90, 1, 11, 0);
Optimization2DX1.SetDemandPiece(12,
110, 110, 1, 12, 0);
Optimization2DX1.SetDemandPiece(13,
110, 110, 1, 13, 0);
Step 2. Set the sheets to cut from (also called stock or REPOSITORY pieces).
Optimization2DX1.NumberOfRepositoryPieces
:= 3;
Optimization2DX1.SetRepositoryPiece(0,
300, 200, 0, 0, 0, 0, 0, 0, 0);
Optimization2DX1.SetRepositoryPiece(1,
300, 200, 0, 0, 0, 0, 1, 0, 0);
Optimization2DX1.SetRepositoryPiece(2,
300, 200, 0, 0, 0, 0, 2, 0, 0);
Step 3. Set other parameters.
Optimization2DX1.BladeWidth := 0;
Optimization2DX1.OptimizationLevel := 50;
Optimization2DX1.RandomSeed := 1;
Optimization2DX1.MaximalCutLength
:= 300;
Step 4. Start the optimization process.
Optimization2DX1.StartGuillotine();
Step 5. Use the OnFinish event to extract the results of optimization.
' this example displays only the first sheet.
' if you want to obtain information about all
sheets just iterate through all of them
' sheets are indexed from 0 to
TotalNumberOfUtilizedRepositoryPieces
' usually the first parameter of the methods is the sheet index
// the variables
var
NoWastes, NoCuttings, NoPieces, i :
integer;
tx, ty, bx, by, thick, rotated :
longint;
poz_x, poz_y : integer;
rep_ID, rep_Index, dem_Index, dem_ID:
longint;
sf_cov : double;
SheetIndex : longint;
// the actual code
Optimization2DX1.SurfaceCovered(SheetIndex,
sf_cov, rep_Index, rep_ID);
eSurfaceCovered.Text :=
FloatToStr(sf_cov);
Image1.Canvas.Rectangle(0, 0, 300,
200); // clear the drawing surface
Optimization2DX1.NumberOfCuttings(SheetIndex,
NoCuttings, rep_Index, rep_ID);
for i := 0 to
NoCuttings - 1 do
begin
Optimization2DX1.GetCut(SheetIndex, i, tx, ty,
bx, by, thick, rep_Index, rep_ID);
Image1.Canvas.MoveTo(tx, ty);
Image1.Canvas.LineTo(bx, by); // draw the cuttings
end;
// utilized rectangles
Optimization2DX1.NumberOfUtilizedDemandPieces(SheetIndex,
NoPieces, rep_Index, rep_ID);
for i := 0 to NoPieces
- 1 do
begin
Optimization2DX1.GetUtilizedDemandPiece(SheetIndex,
i, tx, ty, bx, by, rotated, rep_Index, dem_Index, rep_ID, dem_ID); //
get the position of each piece
poz_x := (bx+tx)
div 2 - Image1.Canvas.TextWidth(FloatToStr(bx-tx)+'x'+FloatToStr(by-ty))
div 2;
poz_y := (by+ty)
div 2 - Image1.Canvas.TextHeight(FloatToStr(bx-tx)+'x'+FloatToStr(by-ty))
div 2;;
Image1.Canvas.TextOut(poz_x, poz_y, FloatToStr(abs(bx - tx)) + 'x' +
FloatToStr(abs(by - ty)));
end;
// waste rectangles
Optimization2DX1.NumberOfWastePieces(SheetIndex,
NoWastes, rep_Index, rep_ID);
for i := 0 to NoWastes
- 1 do
begin
Optimization2DX1.GetWastePiece(SheetIndex,
i, tx, ty, bx, by, rep_Index, rep_ID); // get each wastes
lbWaste.AddItem(FloatToStr(abs(tx - bx)) + ' x ' + FloatToStr(abs(by -
ty)), nil);
poz_x := (bx
+ tx) div 2 - Image1.Canvas.TextWidth('w') div 2;
poz_y := (by
+ ty) div 2 - Image1.Canvas.TextHeight('w') div 2;
Image1.Canvas.TextOut(poz_x, poz_y, 'w'); // draw a text "w" in the
middle of the waste
end;