mirror of
https://github.com/ajisaacs/OpenNest.git
synced 2026-11-26 20:37:42 -05:00
feat(engine): run Raster as a Default candidate
Default now runs Rectangles, Raster, Circles, then Irregular, so a stopped or time-limited search holds an irregular plan within seconds. Ranking is unchanged; Raster is last in tie-break order and wins only with a strictly better score. The cutout pipeline tests keep their "ordinary solve cannot fit the insert" precondition for Irregular only, since Raster nests in holes. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
dfee19d24b
commit
4280d568b4
10 files changed
+40
-29
No files matched your search
@@ -64,7 +64,10 @@ public class CutoutPipelineHoledInsertTests
|
||||
public void StrapWithBoltHolesGoesInTheFrameWindow(string engine)
|
||||
{
|
||||
var request = Request(engine, Frame(), Strap());
|
||||
Assert.Equal(NestJobStatus.Incomplete, NestPipeline.RunWithoutCutouts(request).Status);
|
||||
// Irregular's ordinary solve never nests a part in a hole; Default's can, through Raster,
|
||||
// which keeps cutouts open, so only the bundled result is checked for it.
|
||||
if (engine == "Irregular")
|
||||
Assert.Equal(NestJobStatus.Incomplete, NestPipeline.RunWithoutCutouts(request).Status);
|
||||
|
||||
var result = NestPipeline.Run(request);
|
||||
|
||||
|
||||
@@ -45,8 +45,10 @@ public class CutoutPipelineRunTests
|
||||
public void OrdinaryRunPlacesAnInsertInsideItsFrameThatTheOrdinarySolveCannotFit(string engine)
|
||||
{
|
||||
var request = Request(engine);
|
||||
var baseline = NestPipeline.RunWithoutCutouts(request);
|
||||
Assert.Equal(NestJobStatus.Incomplete, baseline.Status);
|
||||
// Irregular's ordinary solve never nests a part in a hole; Default's can, through Raster,
|
||||
// which keeps cutouts open, so only the bundled result is checked for it.
|
||||
if (engine == "Irregular")
|
||||
Assert.Equal(NestJobStatus.Incomplete, NestPipeline.RunWithoutCutouts(request).Status);
|
||||
|
||||
var result = NestPipeline.Run(request);
|
||||
Assert.True(result.IsValid, string.Join("; ", result.Violations));
|
||||
|
||||
@@ -39,11 +39,11 @@ public class DefaultNestingEngineTests
|
||||
[Fact]
|
||||
public void BuiltInDefaultRunsIrregularLast()
|
||||
{
|
||||
// Rectangles is the cheap, always-valid fallback: under a limit it must have reported
|
||||
// its plan before the slower Irregular search starts, and Irregular, which may search
|
||||
// until cancelled, must not keep Circles from running. Candidates stay in tie-break
|
||||
// order Irregular, Rectangles, Circles.
|
||||
Assert.Equal(new[] { 1, 2, 0 }, new DefaultNestingEngine().RunOrder);
|
||||
// Rectangles is the cheap, always-valid fallback and Raster the fast irregular plan:
|
||||
// under a limit both must have reported before the slower Irregular search starts, and
|
||||
// Irregular, which may search until cancelled, must not keep the others from running.
|
||||
// Candidates stay in tie-break order Irregular, Rectangles, Circles, Raster.
|
||||
Assert.Equal(new[] { 1, 3, 2, 0 }, new DefaultNestingEngine().RunOrder);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
|
||||
@@ -301,7 +301,7 @@ public class IrregularSearchUntilCancelledTests
|
||||
public void DefaultUnderATimeLimitReturnsAValidPlanNoWorseThanUnlimited()
|
||||
{
|
||||
// Irregular runs last under Default and searches until the limit; its plans compete
|
||||
// with the Rectangles and Circles results already reported. A limit shorter than the
|
||||
// with the Rectangles, Raster and Circles results already reported. A limit shorter than the
|
||||
// normal search correctly returns an earlier, worse plan, so the limit is scaled from
|
||||
// the measured unlimited solve: seconds on a loaded CI runner, not a fixed constant.
|
||||
var job = MixedJob(false);
|
||||
|
||||
@@ -46,7 +46,7 @@ public static class NestingEngineRegistry
|
||||
// Listed first: the engine front ends use when the caller names none.
|
||||
Register(
|
||||
"Default",
|
||||
"Any job: tries Rectangles, Circles and Irregular and keeps the best",
|
||||
"Any job: tries Rectangles, Raster, Circles and Irregular and keeps the best",
|
||||
() => new DefaultNestingEngine()
|
||||
);
|
||||
|
||||
|
||||
@@ -7,6 +7,7 @@ using System.Threading;
|
||||
using OpenNest.Engine.Jobs;
|
||||
using OpenNest.Engine.NestingEngines.Circles;
|
||||
using OpenNest.Engine.NestingEngines.Irregular;
|
||||
using OpenNest.Engine.NestingEngines.Raster;
|
||||
using OpenNest.Engine.NestingEngines.Rectangles;
|
||||
|
||||
namespace OpenNest.Engine.NestingEngines.Default;
|
||||
@@ -17,10 +18,11 @@ namespace OpenNest.Engine.NestingEngines.Default;
|
||||
/// layout before an invalid one, then the fewest unplaced parts, then the lowest
|
||||
/// <see cref="NestJobCost"/>; remaining ties keep candidate order.
|
||||
///
|
||||
/// Candidates are Irregular, then Rectangles, then Circles. Neither of the first two wins every
|
||||
/// job: Rectangles packs each part as its box, which is often best for plain plates and is a
|
||||
/// cheap, valid fallback for the rest. Circles bids only when every part is round, and otherwise
|
||||
/// returns everything unplaced at once.
|
||||
/// Candidates are Irregular, then Rectangles, then Circles, then Raster. Neither of the first two
|
||||
/// wins every job: Rectangles packs each part as its box, which is often best for plain plates and
|
||||
/// is a cheap, valid fallback for the rest. Circles bids only when every part is round, and
|
||||
/// otherwise returns everything unplaced at once. Raster is a fast irregular nest whose plan comes
|
||||
/// long before Irregular's; it is last in tie-break order, so it wins only by a better score.
|
||||
/// A candidate that throws or returns no result is skipped; when every candidate throws, the
|
||||
/// exception of the first in tie-break order is rethrown. Cancellation stops the search.
|
||||
/// Candidates' plate commits are not forwarded; the chosen result's commits are reported once it
|
||||
@@ -31,9 +33,10 @@ namespace OpenNest.Engine.NestingEngines.Default;
|
||||
/// worse plan after a better one. A candidate result that beats them is reported too, and the
|
||||
/// chosen result is always the last plan reported.
|
||||
///
|
||||
/// Rectangles, the quick and always-valid fallback, runs first, then Circles, then Irregular, so
|
||||
/// a caller that stops the search early, such as <see cref="DeadlineNestingEngine"/>, already
|
||||
/// holds a valid plan, and Irregular can search until cancelled
|
||||
/// Rectangles, the quick and always-valid fallback, runs first, then Raster, then Circles, then
|
||||
/// Irregular, so a caller that stops the search early, such as <see cref="DeadlineNestingEngine"/>,
|
||||
/// already holds a valid plan (an irregular one within seconds), and Irregular can search until
|
||||
/// cancelled
|
||||
/// (<see cref="NestJobOptions.SearchUntilCancelled"/>) last. The choice is made after all have
|
||||
/// run, in candidate (tie-break) order, so the run order never changes it.
|
||||
///
|
||||
@@ -51,8 +54,9 @@ public sealed class DefaultNestingEngine : INestingEngine
|
||||
() => new IrregularNestingEngine(),
|
||||
() => new RectanglesNestingEngine(),
|
||||
() => new CirclesNestingEngine(),
|
||||
() => new RasterNestingEngine(),
|
||||
},
|
||||
new[] { 1, 2, 0 })
|
||||
new[] { 1, 3, 2, 0 })
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
@@ -26,12 +26,12 @@ namespace OpenNest.Mcp.Tools
|
||||
|
||||
/// <summary>Built-in engines with what each suits; a test keeps this in step with the registry.</summary>
|
||||
private const string JobEngines =
|
||||
"Whole-job engine. Default (used when omitted): suits any job; runs Irregular, Rectangles and Circles "
|
||||
"Whole-job engine. Default (used when omitted): suits any job; runs Irregular, Rectangles, Circles and Raster "
|
||||
+ "and keeps the cheapest valid layout. "
|
||||
+ "Irregular: irregular profiles; no-fit-polygon packing into notches and gaps, best-fit pairs. "
|
||||
+ "Rectangles: plain and near-rectangular parts; packs each part as its bounding box, fastest. "
|
||||
+ "Circles: round parts (blanks, washers, flanges); packs each part as its enclosing circle; places nothing when any part is not round. "
|
||||
+ "Raster: a fast first plan of irregular parts, packed on a fine grid; not run by Default. "
|
||||
+ "Raster: a fast first plan of irregular parts, packed on a fine grid; Default's quick first plan. "
|
||||
+ "FlatBar: flat bar, parts about as wide as the bar; each stock cut as one row of parts along its length, shaped ends nested together; not run by Default. "
|
||||
+ "Lattice: many copies of few drawings; lattice fill with pairs and rectangle best-fit. "
|
||||
+ "Strip: Lattice variant laying mixed drawings in strips. "
|
||||
|
||||
@@ -95,7 +95,7 @@ Run `dotnet run --project OpenNest.Console -- --help` for the complete options a
|
||||
|
||||
## Nesting Engines
|
||||
|
||||
Default compares the built-in Irregular, Rectangles and Circles engines and keeps the best valid whole-job layout. Other engines and plug-ins suit particular jobs; see [which engine to use](docs/nesting-engines.md). Desktop Auto Nest, console autonest, MCP autonest, and the API share an independent validation pipeline, including for plug-ins. [Automatic nesting and validation](docs/automatic-nesting.md) explains how callers handle invalid results.
|
||||
Default compares the built-in Irregular, Rectangles, Circles and Raster engines and keeps the best valid whole-job layout. Other engines and plug-ins suit particular jobs; see [which engine to use](docs/nesting-engines.md). Desktop Auto Nest, console autonest, MCP autonest, and the API share an independent validation pipeline, including for plug-ins. [Automatic nesting and validation](docs/automatic-nesting.md) explains how callers handle invalid results.
|
||||
|
||||
## File Format
|
||||
|
||||
|
||||
@@ -30,7 +30,7 @@ Drawing an outline in the plate view and taking the leftover of a cut plate are
|
||||
| Area | Behavior |
|
||||
|---|---|
|
||||
| Irregular engine (and Default through it) | Fills the outline: the stock's usable material (outline less obstacles, eroded by the outline inset below) is the `FrontierPacker`'s `PackBoundary`, the same boundary the cutout packer uses, so every orientation's free region starts inside it |
|
||||
| Rectangles, Circles, FlatBar, the fill strategies (Lattice, Strip, remnants) | Place nothing on an outlined sheet; Default then keeps Irregular's layout. `PlateFillService` throws `PlateFillService.Refusal(plate)` for an outlined plate; every caller checks it first: the desktop's Fill (Ctrl+F on a picked-up part) and Fill Area put the message in the status bar and add nothing, Pattern Tile offers a new plate only, the MCP fill/pack tools return it as an `Error:` result, and the console exits 2 with it unless `--autonest` is given |
|
||||
| Rectangles, Circles, Raster, FlatBar, the fill strategies (Lattice, Strip, remnants) | Place nothing on an outlined sheet; Default then keeps Irregular's layout. `PlateFillService` throws `PlateFillService.Refusal(plate)` for an outlined plate; every caller checks it first: the desktop's Fill (Ctrl+F on a picked-up part) and Fill Area put the message in the status bar and add nothing, Pattern Tile offers a new plate only, the MCP fill/pack tools return it as an `Error:` result, and the console exits 2 with it unless `--autonest` is given |
|
||||
| Layout check and the runner's candidate validation | A part's material must lie inside the usable area; a part in a missing corner or over an obstacle is a violation ("falls outside the outline ... or over one of its obstacles"). The spacing outline, which circumscribes arcs by up to 0.001, finds the candidates and the part's native contour confirms them (`SheetOutline.Holds` with `NativeContours.Region`: arcs circumscribed at 0.000025, clipped to the part's true bounds), as for part spacing, so a round part resting on an edge passes as a square one does. The runner calls the layout check's own test (`NestLayoutCheck.InsideOutline`), so the two accept the same poses. The area budget is the usable area |
|
||||
| Edge spacing | The outline is eroded by the **largest** of the four edge spacings (`NestPlateStock.OutlineInset`), so no outline edge is closer to a part than the rectangle's own sides would be. The rectangular work area still applies and is never larger than that erosion |
|
||||
| Push, clone push placement, settling | A pushed part stops at the edge of the usable area as it stops at the work-area edge: the unusable part of the work area (a missing corner, an obstacle, each grown by the outline inset) is a wall for `Compactor`'s plate pushes (`InteractiveOutline`). The part is measured by the perimeter of its clean material (no leads) with its arcs slid as arcs, so a round part rests on a wall exactly as it rests on the plate edge, where the edge review passes. A bounding-box push (Ctrl-click clone placement, the coarse pass of a settle) rests the box on the wall. A part already lying in a wall, deeper than the review's slack, is not held by it and can be pushed back out; with uneven edge spacing the walls join into one, so such a part is held by none of them |
|
||||
|
||||
@@ -11,11 +11,11 @@ in `OpenNest.Engine/NestingEngines/<Name>/`, its tests in `OpenNest.Engine.Tests
|
||||
|
||||
| Engine | Best for | Method |
|
||||
|---|---|---|
|
||||
| Default | Any job; used when no engine is named | Runs Irregular, Rectangles and Circles, checks each layout with the layout check and keeps the best: valid first, then fewest unplaced parts, then lowest salvage-credited cost, then the largest compactness offcut; remaining ties keep the engine listed first here |
|
||||
| Default | Any job; used when no engine is named | Runs Irregular, Rectangles, Circles and Raster, checks each layout with the layout check and keeps the best: valid first, then fewest unplaced parts, then lowest salvage-credited cost, then the largest compactness offcut; remaining ties keep the engine listed first here |
|
||||
| Rectangles | Plain and near-rectangular plates | Each part packed as the box of its material at its minimum-area rotation, using a maximal-rectangles free list; the sheet that finishes the job is also squeezed into a shorter or narrower bin; stock chosen sheet by sheet by salvage-credited look-ahead cost, and the whole job also run large parts first with the small parts filling their sheets' gaps |
|
||||
| Circles | Round parts: blanks, washers, flanges, gears by their tip circle | Each part packed as its minimum enclosing circle at centers tangent to two of walls, placed discs and clamp keep-outs, with hexagonal and square lattice seeds; bids only when every part is round; stock chosen as Rectangles does, plus whole-job runs preferring each stock and a tail re-plan |
|
||||
| Irregular | Irregular profiles | No-fit-polygon frontier packing with gap filling and best-fit pairs, six whole-job strategy variants (each also keeping a stock that finished the job when the per-sheet estimate passed it over for a plan that ended up dearer) and a tail re-plan, then large-first variants that pack each sheet's large parts before any small one, then grouped variants that pack like parts together, then a banded variant that packs each sheet in full-height strips, each group as its Lattice band or each strip from the largest parts down, with the last sheet of every plan it makes its best packed again as such bands, then a sheet-reduction pass that packs edge parts first and turns a key part by its contacts, then a squeeze that packs the last sheet again, largest part first, in ever shorter strips; under a time limit it first reports a quick plan without Lattice blocks, and after its search keeps trying seeded variants until the limit |
|
||||
| Raster | A fast first plan of irregular parts | Each part rotation rasterized as a bit mask of its material grown by half the part spacing; coarse raster no-fit maps propose positions over the sheet and a grid four times finer settles each one; the job decoded greedily in 48 variants (orders, rotation sets, leftmost or frontier positions) and once offering every variant's sheet each round, stock chosen as Rectangles does, best by Default's ranking kept; not one of Default's candidates |
|
||||
| Raster | A fast first plan of irregular parts | Each part rotation rasterized as a bit mask of its material grown by half the part spacing; coarse raster no-fit maps propose positions over the sheet and a grid four times finer settles each one; the job decoded greedily in 48 variants (orders, rotation sets, leftmost or frontier positions) and once offering every variant's sheet each round, stock chosen as Rectangles does, best by Default's ranking kept; Default's last candidate |
|
||||
| FlatBar | Flat bar: parts about as wide as the bar | Each stock read as a bar and cut in one row: the CutList cut-list packer and a best-fill search on part lengths less their self-nesting gain, then a slide-left pass that nests shaped ends and refills freed length; stock chosen bar by bar by whole-plan cost |
|
||||
| Lattice, Strip, Vertical Remnant, Horizontal Remnant | Many copies of a few parts | The fixed placement strategies behind interactive fill; Lattice is the multi-phase lattice fill (linear, pairs, rectangle best-fit, remainder; the pairs phase fills the strip its grid leaves with rows of pairs when they hold more than single parts, and also tiles herringbone pairs: the part turned so a hull edge lies along a sheet axis, nested into its own row, with every other row reversed), and the remnant strategies run it ranked to keep the largest drop. In whole jobs, all four place a plate with any fixed or bounded part rotation by the rotation-aware ordered placer instead |
|
||||
|
||||
@@ -53,10 +53,11 @@ same way, in place of the two orders above.
|
||||
|
||||
Neither Irregular nor Rectangles wins every job, even within its own lane, so Default runs both
|
||||
rather than choosing by part shape; Rectangles adds little time and is also the fallback when an
|
||||
Irregular layout fails the check. Default runs Rectangles first, then Circles, then Irregular, so
|
||||
a search stopped early already holds a valid plan and Irregular can keep searching last; it
|
||||
chooses only after all have run, in table order (Irregular, Rectangles, Circles), so the run
|
||||
order never changes the choice. A candidate that throws is skipped. Default routes the whole job:
|
||||
Irregular layout fails the check. Default runs Rectangles first, then Raster, then Circles, then
|
||||
Irregular, so a search stopped early already holds a valid plan, an irregular one within seconds
|
||||
from Raster, and Irregular can keep searching last; it chooses only after all have run, in the
|
||||
order Irregular, Rectangles, Circles, Raster, so the run order never changes the choice and Raster
|
||||
wins only with a strictly better score. A candidate that throws is skipped. Default routes the whole job:
|
||||
engines cannot share a sheet, so a job mixing plain and irregular parts goes to both engines whole.
|
||||
Circles is a third candidate that bids only on round jobs (see below), so a job mixing round and
|
||||
other parts goes to Irregular and Rectangles.
|
||||
@@ -591,7 +592,8 @@ On seven real jobs (one to 292 parts, `--parallel 1`, 6" minimum salvage) every
|
||||
was valid. It matched Irregular's sheet count on five, in 0.6 to 2.3 s where Irregular took 11 to
|
||||
78 s, at under 1 to 4% more salvage-credited cost; it took a third sheet where Irregular used two on a
|
||||
job of ten large plates, and 24 s on a job offering seven stock sizes. It suits a quick look at a
|
||||
job, not a final layout, and is not one of Default's candidates.
|
||||
job, not a final layout. Default runs it second, after Rectangles, so its plan is shown early,
|
||||
and ranks it last, so it is chosen only when its layout scores strictly better.
|
||||
|
||||
Packing tighter than the spacing (masks grown by half the spacing, then half and one cell under)
|
||||
and opening the gaps with Fix Spacing was tried on the same jobs: it saved under 0.1% of total
|
||||
|
||||
Reference in new issue
Block a user