寻求RinSim中可遍历road model、穿越实体的抽象逆向移动对象
Hey there! Let's tackle your question about finding or building a RinSim component that fits your needs:
RinSim doesn't have an out-of-the-box abstract component that checks all your boxes, but there are core abstractions you can leverage as a starting point:
RoadGraph: This is the foundational abstract representation of the road network in RinSim. It’s designed to be traversed (via itsRoadNodeandRoadEdgeelements), doesn’t have any physical presence, and makes reverse traversal straightforward—since you can easily access incoming edges instead of outgoing ones to move against the road’s default direction.Path/Route: These are abstract classes for defining paths on the road model. They support reversing (by flipping the order of nodes in the path) and don’t tie into the physics engine, so they naturally "pass through" other physical objects (since they’re just logical paths, not tangible entities).
Since you need a purpose-built abstract object, wrapping these core components into a custom class is the way to go. Here’s a quick example of what that could look like:
import com.github.rinde.rinsim.core.model.road.RoadGraph; import com.github.rinde.rinsim.core.model.road.RoadNode; import com.github.rinde.rinsim.core.model.road.RoadEdge; import java.util.Collection; public class AbstractRoadTraverser { private final RoadGraph roadGraph; private RoadNode currentPosition; // Initialize with the road graph and starting node public AbstractRoadTraverser(RoadGraph graph, RoadNode startNode) { this.roadGraph = graph; this.currentPosition = startNode; } // Traverse to the next node, with a flag for reverse direction public void move(boolean reverseDirection) { Collection<RoadEdge> edges = reverseDirection ? roadGraph.getIncomingEdges(currentPosition) : roadGraph.getOutgoingEdges(currentPosition); // Pick the next edge (you can adjust this logic to fit your traversal rules) if (!edges.isEmpty()) { RoadEdge nextEdge = edges.iterator().next(); currentPosition = reverseDirection ? nextEdge.getFrom() : nextEdge.getTo(); } } // Get the current abstract position public RoadNode getCurrentPosition() { return currentPosition; } }
This class:
- Traverses the
RoadGraphwithout any physical presence - Supports reverse movement by switching between incoming/outgoing edges
- Automatically "passes through" other physical objects because it doesn’t register with the physics engine (so collisions aren’t checked)
You won’t find a pre-built component that exactly matches your abstract, non-physical traverser needs, but RinSim’s core road model abstractions are flexible enough to build this quickly without reinventing the wheel.
内容的提问来源于stack exchange,提问作者blah_crusader

