Question: I have this ASP code: % Input: road ( b , a ) . road ( c , b ) . road ( g ,
I have this ASP code:
Input:
roadba
roadcb
roadgb
roadbg
roadaf
roadfb
roadbe
roadec
roadcd
blockedcd
starta
Define cleanable roads: Roads that are not blocked
cleanableA B : roadA B not blockedA B
The sweeper can traverse cleanable roads
reachableA B : cleanableA B
Define the route: inrouteA B means the sweeper uses the road from A to B
inrouteA B : reachableA B : reachableA B
Ensure all cleanable roads are either included or excluded from the route
: cleanableA B not inrouteA B
Define visited locations
visitedX : startX
visitedY : inrouteX Y visitedX
Ensure all endpoints of cleanable roads are visited
: cleanableX not visitedX
: cleanable X not visitedX
Ensure the route is a closed loop: sweeper must return to its starting point
: startS not visitedS
Minimize the number of streets cleaned more than once
#minimize inrouteA B : reachableA B
#show inroute
#show visited
Which is the solution for my problem described in the image attached
The code outputs:
visiteda visitedf visitedb visitedg visitede visitedc inrouteaf inroutefb inroutebg inroutebe inrouteec inroutegb inroutecb inrouteba
it should output:
visiteda visitedf visitedb visitedg visitedb visitede visitedc inrouteaf inroutefb inroutebg inroutegb inroutebe inrouteec inroutecb inrouteba
In the attached handdrawn image is the problem we are trying to solve we want the general solution, but this graph is the perfect test for verification
The graph in the image can be described by the input:
roadba
roadcb
roadgb
roadbg
roadaf
roadfb
roadbe
roadec
roadcd
blockedcd
starta
The problem with the current solution is that: we dont have a SinglePathPostmanEuler Encoding
This problem is essentially the Route Inspection Problem aka Chinese Postman Problem or an Eulerlike path problem on a directed graph:
You must cover clean each edge at least once.
You want to minimize how many edges get traversed more than once.
You want a single cycle start end
If the directed graph were strictly Eulerian every node has equal indegree and outdegree, and the graph is strongly connected in the relevant subgraph then you could do an Euler tour with zero repeats. But whenever a graph is not balanced, you must duplicate edges to patch up indegree vs outdegree, or to remain strongly connected.
Crucially, you also need to encode the idea of a single contiguous route. Merely saying include all edges, and we must visit them all at least once does not guarantee that in the final solution, after traveling bg your next move is forced to be gb
Please fix my solution to include this funcitonality.
Test it with the input:
roadba
roadcb
roadgb
roadbg
roadaf
roadfb
roadbe
roadec
roadcd
blockedcd
starta
The output should be:
visiteda visitedf visitedb visitedg visitedb visitede visitedc inrouteaf inroutefb inroutebg inroutegb inroutebe inrouteec inroutecb inrouteba
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
