Forums: » Register « |  Free Tools |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support |
 User Name: Password: Remember me

New Free Tools on Dev Shed!
We're Excited to announce that Dev Shed now has 70 free tools on the site. To learn more, click here!

 Dev Shed Forums Sponsor:
#1
May 15th, 2013, 09:07 AM
 rockyworld1
Registered User

Join Date: May 2013
Posts: 1
Time spent in forums: 28 m 57 sec
Reputation Power: 0
Astar search

Hey guys,
I have some homework which requires me to do a star search on a series of job courier deliveries.
This is the spec: http://pastebin.com/mWA4BrkB
We've been told there is no set grid and for the state space it is all the set of solutions possible.
This is what I have so far:
Node -
Code:
```
/* Class which describes a single node with an x and y coordinate */
public class Node {

/* Constants defined here for clarity. */
private int xCoord;
private int yCoord;

/* Node Constructor */
public Node (int aXCoord, int aYCoord) {

xCoord = aXCoord;
yCoord = aYCoord;
}

/* Methods */
/**
* Gets the x coordinate of the node.
* @return x coordinate
*/
public int getXCoord () {

return this.xCoord;
}

/**
* Gets the y coordinate of the node
* @return y coordinate
*/
public int getYCoord () {

return this.yCoord;
}
}
```

which is just an x and y coordinate
Edge -
Code:
``` import java.lang.Math;

/* Class that defines an Edge between two nodes */
public class Edge {

/* Constants defined here for clarity */
private Node lastJobNode;
private Node newJobNode;
private double betweenJobDist;

/* Constructor */
public Edge (Node jobFinish, Node jobStart) {

lastJobNode = jobFinish;
newJobNode = jobStart;
}

/* Methods */

/**
* Gets the travel distance between two jobs defined in the edge
* @return betweenJobDist
*/
public double getTravDistBetweenJobs () {

// for simplicity we calculate everything to square root first
double toAbs = Math.sqrt(newJobNode.getXCoord() - lastJobNode.getXCoord()) + (newJobNode.getYCoord() - lastJobNode.getXCoord());

// then return the absolute value of the previous result
return betweenJobDist = Math.abs(toAbs);
}

public Node getConnectedEdge () {

return this.newJobNode;
}
}
```

which is a connector from the end of a job to the beginning of a new job
Job -
Code:
``` import java.lang.Math;

/* Class that defines the job between the start and end of a job */
public class Job {

/* Constants declared here for clarity */
private static double jobTravelDist;
private static Node start;
private static Node end;

/* Constructor */
public Job (Node jStart, Node jEnd) {

start = jStart;
end = jEnd;
}

/* Methods */
/**
* Gets the travel distance between the start and end of a job
* @return travelDistance
*/
public double getJobTravDist () {

// for simplicity we calculate everything to square root first
double toAbs = Math.sqrt(end.getXCoord() - start.getXCoord()) + (end.getYCoord() - start.getXCoord());

// then return the absolute value of the previous result
return jobTravelDist = Math.abs(toAbs);
}

public Node getJobEnd() {

return this.end;
}

}
```

which is a job which has a start and an end node
CourierDelivery -
Code:
```import java.io.FileNotFoundException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.PriorityQueue;
import java.util.Scanner;
import java.util.Set;

/* Main file which reads in input. */
public class CourierDelivery {

/* Constants defined here for clarity. */
private static HashMap<Node, Node> nodeList;

/* Main */
public static void main (String[] args) {

try {
// scans in input file
Scanner sc = new Scanner(new FileReader("resources/input1"));
CourierDelivery cDSystem = new CourierDelivery();
// while the input file has another token
while (sc.hasNext()) {
// string used for comparison
String nxt = sc.next();

// if it equals to Job
if ("Job".equals(nxt)) {

// gets the next int to accept and create start coordinates
int xStart = sc.nextInt();
int yStart = sc.nextInt();
Node startNode = new Node(xStart, yStart);

// progresses it forward one string to accept and create destination coordinates
sc.next();
int xDest = sc.nextInt();
int yDest = sc.nextInt();
Node endNode = new Node (xDest, yDest);

// inserts the above two nodes to the map
cDSystem.createMapXY (startNode, endNode);

// creates a job for the start and end nodes
Job newJob = new Job (startNode, endNode);
} else {
System.out.println("no");
}
//cDSystem.printMap();
}
}
catch (FileNotFoundException e) {}
}

/* Constructor */
public CourierDelivery () {

nodeList = new HashMap<Node, Node>();
}

/* Methods */
/**
* Creates a mapping for a job from the start to end node
* @param startNode	where the job starts
* @param endNode	where the job ends
*/
public void createMapXY (Node startNode, Node endNode) {

nodeList.put(startNode, endNode);
}

public void printMap () {

for (Node startNode : nodeList.keySet()) {
System.out.print(startNode.getXCoord() + ", " + startNode.getYCoord());
System.out.print(" -> ");
for (Node endNode : nodeList.values()) {
System.out.println(endNode.getXCoord() + ", " + endNode.getYCoord());
}
}
}
public void AStarSearch (Node start, Set emptySet) {

PriorityQueue<Node> openList = new PriorityQueue<Node>();

while (!openList.isEmpty()) {
Node current = openList.poll();
}```

I don't really understand how to write the a star search function. I've tried looking at the psuedo code on wiki but it just confuses me. I've started it but I'm not entirely sure what to write for the comparison to check whether I've achieved the goal.
Any help provided would be greatly appreciated.

 Viewing: Dev Shed Forums > Programming Languages > Java Help > Astar search

## Developer Shed Advertisers and Affiliates

 Thread Tools Search this Thread Search this Thread: Advanced Search Display Modes Rate This Thread Linear Mode Rate This Thread: 5 : Excellent 4 : Good 3 : Average 2 : Bad 1 : Terrible

 Posting Rules You may not post new threads You may not post replies You may not post attachments You may not edit your posts vB code is On Smilies are On [IMG] code is On HTML code is Off
 View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox Forum Jump Please select one User Control Panel Private Messages Subscriptions Who's Online Search Forums Forums Home -------------------- Programming Languages    PHP Development        PHP FAQs and Stickies    Perl Programming        Perl FAQs and Stickies    C Programming        C Programming FAQs and Stickies    Java Help        Java FAQs    Python Programming        Python Programming FAQs    Ruby Programming        Ruby Programming FAQs    Game Development        Game Development FAQs Programming Languages - More    ASP Programming        ASP Programming FAQs    .Net Development        .Net Development FAQs    Visual Basic Programming        Visual Basic Programming FAQs    Software Design        Software Design FAQs    ColdFusion Development        ColdFusion Development FAQs    Delphi Programming        Delphi Programming FAQs    Regex Programming        Regex Programming FAQs    XML Programming        XML Programming FAQs    Other Programming Languages        Other Programming Languages FAQs Web Design    HTML Programming        HTML Programming FAQs    JavaScript Development        JavaScript Development FAQs    CSS Help        CSS Help FAQs    Flash Help        Flash Help FAQs    Photoshop Help        Photoshop Help FAQs    Web Design Help        Web Design Help FAQs    Website Critiques        Website Critiques FAQs    Search Engine Optimization        Search Engine Optimization FAQs Mobile Programming    Mobile Programming        Mobile Programming FAQs    iPhone SDK Development        iPhone SDK Development FAQs    Android Development        Android Development FAQs    BlackBerry Development        BlackBerry Development FAQs Web Site Management    Business Help        Business Help FAQs    Development Software        Development Software FAQs    Scripts        Scripts FAQs Databases    Database Management        Database Management FAQs    DB2 Development        DB2 Development FAQs    MySQL Help        MySQL Help FAQs    PostgreSQL Help        PostgreSQL Help FAQs    Firebird SQL Development        Firebird SQL Development FAQs    MS SQL Development        MS SQL Development FAQs    Oracle Development        Oracle Development FAQs    LDAP Programming        LDAP Programming FAQs System Administration    Mail Server Help        Mail Server Help FAQs    Apache Development        Apache Development FAQs    Security and Cryptography        Security and Cryptography FAQs    Antivirus Protection        Antivirus Protection FAQs    DNS        DNS FAQs    IIS        IIS FAQs    Networking Help        Networking Help FAQs    FTP Help        FTP Help FAQs Operating Systems    BSD Help        BSD Help FAQs    Linux Help        Linux Help FAQs    UNIX Help        UNIX Help FAQs    Windows Help        Windows Help FAQs    Mac Help        Mac Help FAQs Web Hosting    Web Hosting        Web Hosting FAQs    Free Web Hosting        Free Web Hosting FAQs    Web Hosting Requests        Web Hosting Requests FAQs    Web Hosting Offers        Web Hosting Offers FAQs Computer Hardware    Computer Hardware    CPUs        CPUs FAQs    Cooling        Cooling FAQs    Embedded Programming        Embedded Programming FAQs    Motherboards        Motherboards FAQs    Multimedia Hardware        Multimedia Hardware FAQs Other    Dev Shed Lounge        Dev Shed Lounge FAQs    Development Articles        Development Articles FAQs    Beginner Programming        Beginner Programming FAQs    Hire A Programmer        Hire A Programmer FAQs    Project Help Wanted        Project Help Wanted FAQs Latest News Updated Hourly    Technology News    Business News    Science News Forum Information    Forum Rules/Guidelines        Forum Rules/Guidelines FAQs    Forum Announcements        Forum Announcements FAQs    Dev Shed Gaming Center        Go to the Dev Shed Battle Arena        Go to the Dev Shed Arcade Games        Go to the Legend of the Green Dragon    Suggestions & Feedback        Suggestions & Feedback FAQs

 Forums: » Register « |  Free Tools |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support |