如何在RinSim中从Depot移除Parcel并支持Vehicle拾取?
Got it, let's break down how to solve this. I’ve tinkered with RinSim before, and while addParcelIn() is straightforward, the direct parcel removal method isn’t always front-and-center in the docs. Here are a few reliable approaches:
Check for Undocumented (or Newly Added) Removal Methods
First, double-check your RinSim version. Some newer builds (4.0+) added a publicremoveParcel(Parcel parcel)method to the Depot class that might’ve slipped past your initial search. If it’s available, just call it directly:depot.removeParcel(targetParcel);If your IDE throws an error, try digging into the Depot class source code (most open-source builds let you inspect this) — sometimes methods are package-private but still usable if you’re in the same module.
Work Around by Updating the Parcel’s State
If no direct remove method exists, you can manually adjust the parcel’s state to detach it from the depot. RinSim’s parcels rely on state enums (likeParcelState) to determine if they’re available for pickup. Try:targetParcel.setState(ParcelState.AVAILABLE); // Optional: Move the parcel to a visible position near the depot targetParcel.setPosition(new Point(depot.getPosition().getX() + 10, depot.getPosition().getY()));This marks the parcel as no longer tied to the depot’s storage, so your vehicle’s pickup logic should recognize it as available.
Extend the Depot Class to Add Custom Removal Logic
If all else fails, create a custom Depot subclass that tracks parcels and adds your own remove method:public class RemovableDepot extends Depot { private final Set<Parcel> storedParcels = new HashSet<>(); @Override public void addParcelIn(Parcel parcel) { super.addParcelIn(parcel); storedParcels.add(parcel); } public boolean removeStoredParcel(Parcel parcel) { if (storedParcels.remove(parcel)) { parcel.setState(ParcelState.AVAILABLE); return true; } return false; } }Use this custom depot in your simulation instead of the default one, and you’ll have full control over adding/removing parcels as needed.
内容的提问来源于stack exchange,提问作者blah_crusader

