Expand description
§fieldopt-core
Field-survey design under real field cost. The crate provides the
computational pieces behind the R package fieldopt: travel matrices,
GRASP routing of field work, spatially balanced sampling with the local
pivotal method, Horvitz-Thompson estimation with the local-mean variance
estimator, and cost-aware allocation across strata or frames. It has no
dependencies and every randomised step is reproducible from a seed.
use fieldopt_core::distance::euclidean_matrix;
use fieldopt_core::routing::{grasp_routes, GraspOptions, RouteLimits};
use fieldopt_core::sampling::{inclusion_probabilities, local_pivotal};
// a 6 x 6 grid of segments plus a depot at the origin
let mut x = vec![0.0]; let mut y = vec![0.0];
for i in 0..36 { x.push(1.0 + (i % 6) as f64); y.push(1.0 + (i / 6) as f64); }
let m = euclidean_matrix(&x, &y).unwrap();
// select 12 segments, spatially balanced, with equal probabilities
let coords: Vec<f64> = (1..37).flat_map(|i| vec![x[i], y[i]]).collect();
let pi = inclusion_probabilities(&vec![1.0; 36], 12).unwrap();
let sampled = local_pivotal(&coords, 2, &pi, 1).unwrap();
let units: Vec<usize> = (0..36).filter(|&i| sampled[i]).map(|i| i + 1).collect();
// route the field work from the depot with at most 5 segments per day
let limits = RouteLimits { max_length: f64::INFINITY, max_stops: 5 };
let sol = grasp_routes(&m, 0, &units, limits, GraspOptions::default()).unwrap();
assert_eq!(sol.routes.iter().map(|r| r.len()).sum::<usize>(), 12);
assert!(sol.total >= sol.lower_bound);Re-exports§
pub use allocation::allocate_for_budget;pub use allocation::allocate_for_variance;pub use allocation::Allocation;pub use allocation::Stratum;pub use distance::euclidean_matrix;pub use distance::haversine_matrix;pub use distance::Matrix;pub use dualframe::dual_frame_allocation;pub use dualframe::Domain;pub use dualframe::DualFrame;pub use dualframe::DualFrameAllocation;pub use dualframe::Target;pub use estimation::ht_total;pub use estimation::local_mean_variance;pub use estimation::srs_variance;pub use routing::grasp_routes;pub use routing::route_length;pub use routing::GraspOptions;pub use routing::RouteLimits;pub use routing::Solution;pub use sampling::inclusion_probabilities;pub use sampling::local_pivotal;pub use spatial::hilbert_order;pub use spatial::systematic_replicates;pub use twostage::two_stage_for_budget;pub use twostage::two_stage_for_variance;pub use twostage::TwoStage;pub use twostage::TwoStageAllocation;
Modules§
- allocation
- Cost-aware allocation across strata (or frames treated as strata).
- distance
- Travel matrices from coordinates.
- dualframe
- Dual-frame allocation (Hartley 1962, 1974).
- estimation
- Design-based estimation for the sample.
- rng
- A small, dependency-free, seedable pseudo-random generator.
- routing
- Routing of field work: one team (a travelling-salesman tour from a depot) or several teams or days (vehicle routes with a maximum length and a maximum number of stops per route).
- sampling
- Probability sampling of field units.
- spatial
- Spatially ordered systematic sampling.
- twostage
- Two-stage allocation with a cost function (Cochran 1977, Section 10.6).