Skip to content

AcresOptimizer.h#

Acres/Source/Acres/AcresOptimizer.h Generated

Run Optimizer: three planning tools that run from the menu in well under a second.

All three work on the fields, tractor and weather configured in the menu (an FAcresSession) and fill one FAcresOptResult: a value per field for the result map, summary lines, and files written to Saved/Optimizer/<stamp>-<scenario>/ (fields.csv, fields.geojson, result.json).

  • "plan": field operation plan. Picks the pass direction for each field (fewest passes and turns), orders the fields along the farm roads starting at the Beck lot (nearest neighbour, then 2-opt) and totals time and fuel.
  • "traction": traction and fuel setup. For each field, searches ballast, speed and gear for the lowest cost per hectare while keeping drivetrain wheel slip inside a target band and a 15 % engine torque reserve.
  • "harvest": harvest timing against rain. Steps the weather model hour by hour, tracks soil water and grain moisture per field, and schedules one machine field by field.

The models are steady-state engineering estimates, not calibrated against measurements: draft from ASABE D497.7 (the simulator's implement table, AcresSim::FImplementType), traction from the simulator's own tyre-soil functions and drive layout (AcresVehicleModel.h), fuel from the same Willans line the session log uses, grain moisture from the ASABE D245.6 modified Henderson equation. See Documentation/Modelling/optimizer.md for the equations.

Everything here is plain C++ plus Unreal containers (TArray = std::vector, FString = string, FVector2D = 2D double vector). It runs on the game thread when the user presses Run and touches no Unreal world objects.

FAcresOptSetup#

struct FAcresOptSetup

The best machine setup found for one field by the traction search.

When no setup keeps slip inside the band, the one closest to the band is kept and Note explains why. bFeasible is false only when the tractor cannot pull the implement at all on that field.

Name Type Unit Default Description
bFeasible bool false True when a working setup exists (possibly outside the slip band, see Note).
Note FString Human-readable reason when the setup is a compromise or impossible; empty otherwise.
Gear int 0 Forward gear, 1-based (1 = slowest of the 16).
Rpm double 0 Engine speed, rpm.
SpeedKmh double 0 Ground speed, km/h.
BallastKg double kg 0 Added ballast, kg (45 % front).
Slip double 0 Drivetrain slip as a fraction (0.1 = 10 %).
DraftKN double kN 0 Implement pull, kN.
EngineKw double kW 0 Engine power, kW.
FuelLph double L/h 0 Fuel use, L/h.
FuelLHa double 0 Fuel per hectare, L/ha.
CostHa double 0 Fuel plus operator/machine cost, $/ha.
HaH double 0 Field capacity, ha/h.
TractiveEff double 0 Drawbar power / wheel power, 0-1.
RutCm double cm 0 Rear-tyre sinkage, cm.

FAcresOptField#

struct FAcresOptField

One field in an optimizer result: what it is, the setup found for it, and the scenario's numbers.

Name Type Unit Default Description
Id int 0 Field number from fields.json (F01..F59 -> 1..59).
Cover FString Land cover in the survey (corn, soybean, empty).
Crop FString Crop after menu overrides (corn, soybean, potato; empty if none).
Soil FString Soil label (SSURGO map unit symbol or preset name).
Texture FString "fine", "medium" or "coarse".
AreaHa double 0 Field area, ha.
Wetness double .5 Start wetness (0 wilting point, 1 field capacity, up to 1.3).
Theta double .25 Volumetric water content derived from Wetness and the soil, m3/m3.
PolygonM TArray&lt;FVector2D> m Field outline in world metres (X east, Y south), not closed (last point != first point).
CentroidM FVector2D m Mean of the outline points, world metres.
Operation FString Operation actually run on this field (the harvest operation digs potato fields: "potato_digger").
WidthM double m 0 Working width used on this field, m.
Setup FAcresOptSetup Result of the traction search for this field.
HeadingDeg double ° 0 Pass direction in the field frame, degrees.
WorkH double 0 Time in the field incl. turns and headland laps, h.
FuelL double L 0 Fuel for the field, L.
PassKm double 0 Total pass length, km.
Passes int 0 Number of parallel passes.
Turns int 0 Number of headland turns.
Order int 0 Position in the plan's route, 1-based; 0 = skipped (too wet or no workable setup).
ArriveH double -1 Hours from start when the machine reaches the field (plan).
StartH double -1 Harvest start and end, hours from the harvest timeline origin, -1 if not harvested.
EndH double -1 See above.
GrainMoisture double 0 Moisture at harvest (or at the end of the horizon), % wet basis.
LossPct double % 0 Grain loss (handling + standing), %.
Status FString Why the field was skipped or delayed; empty when all is well.
Value double 0 Number used to colour the map for the current scenario (order, $/ha or start hour).
Label FString Short label drawn on the map ("#3 0.4 h", "11.2 L/ha ...", "wait").

FAcresOptResult#

struct FAcresOptResult

Everything one optimizer run produced. Filled by FAcresOptimizer::Run and drawn by the menu's result page.

Name Type Unit Default Description
Scenario FString "plan", "traction" or "harvest".
Operation FString Implement id ("chisel", "cultivator", "disk", "moldboard", "planter", "potato_digger", "harvest"; under "harvest" potato fields use "potato_digger", see FAcresOptField::Operation).
Title FString Heading for the result page.
Folder FString Absolute output folder.
Summary TArray&lt;FString> One-line results shown under the title.
Notes TArray&lt;FString> Caveats shown in small print.
Fields TArray&lt;FAcresOptField> Every field considered, workable or not.
Route TArray&lt;FVector2D> Plan scenario: road route as a polyline in world metres, starting at StartM.
StartM FVector2D m Where the route starts (the Beck lot entrance), world metres.
ValueName FString What Value means for this scenario ("order", "$/ha", "start (h)").
ValueMin, ValueMax double ValueMin, ValueMax: range of Value over the fields, used to scale map colours.
bLowIsGood bool true True when a low Value is the good end of the colour scale.
HorizonStartDay double 0 Reserved; the harvest timeline origin is Year/Month/Day/StartHour.
Year, Month, Day int Harvest timeline origin date (local).
StartHour double 10 Harvest timeline origin hour, local time (10.5 = 10:30).

FAcresOptimizer#

class FAcresOptimizer

Entry points of the optimizer. Stateless; all functions are static.

Example

FAcresOptResult Result;
FString Error;
if (FAcresOptimizer::Run(Session, Result, Error))
{
    FAcresSession ReplaySession;
    FAcresOptimizer::PrepareVisualization(Session, Result, Result.Fields[0].Id, ReplaySession, Error);
}

FAcresOptimizer::Run#

Runs the scenario selected in the session's Optimize tab ("opt:scenario").

Reads tractor.json, soils.json, soil_units.u8, site.json (roads) and farm.json from Content/Simulation, evaluates every matching field, orders the workable ones along the roads and, for the harvest scenario, steps the weather model hour by hour. Writes fields.csv, fields.geojson (WGS84 polygons) and result.json to a new folder under Saved/Optimizer/.

Argument Description
Session The menu's configuration (fields, tractor, weather and "opt:*" values).
Out Filled with the result. Any previous content is replaced.
Error Set to a one-line message when the run fails.

Returns: True on success. False when the tractor config is unusable, the slip band is empty, or no field matches the selection; Error says which.

static bool Run(const FAcresSession& Session, FAcresOptResult& Out, FString& Error);

FAcresOptimizer::PrepareVisualization#

Turns one field's plan into a replay the simulator can drive (the menu's "Visualize" button).

Builds a coverage path over the field: parallel passes at the planned heading, visited in skip-row blocks so each U-turn fits the turning circle, omega turns for leftovers. Writes it as <result folder>/visualize-F<id>.csv (time_s, speed_mps, curvature_1pm, ue_x_m, ue_y_m, implement, gear) and returns a copy of the session set up to replay it: ballast added to the tractor mass, the implement and its draft, and, for harvest plans, the clock moved to the planned start with the rain event shifted to match.

Argument Description
Session The configuration the result was computed from.
Result A result from Run.
FieldId Field to visualize (FAcresOptField::Id).
OutSession Receives the replay session; pass it to FAcresSession::Prepare with the Replay mode.
Error Set when the field is unknown, has no workable setup or is too small for a path.

Returns: True when the CSV was written and OutSession is ready.

static bool PrepareVisualization(const FAcresSession& Session, const FAcresOptResult& Result, int FieldId, FAcresSession& OutSession, FString& Error);

FAcresOptimizer::TimeLabel#

Formats a time on the harvest timeline for display.

Argument Description
R Result whose Year/Month/Day/StartHour define the timeline origin.
Hours Hours after the origin.

Returns: Local date and time such as "Thu 16 Jul 09:00".

static FString TimeLabel(const FAcresOptResult& R, double Hours);