ACO for finding best paths on a graph.

hello,
i am trying to use aco alg to print shortest path from a specified source node to a destination node. i have created a graph where i have all the vertices (array of strings) and edges(neighbours) stored. I am trying to get the ants to trail randomly on the connected edges from start to dest and then return the route.please can someone give me some advice??.
my code is as follows,...
public class ACOLevel7 {
     private static myGraph g = new myGraph();
     public static void main(String[] args) {
          String start = "";
          String finish = "";
     ACOLevel7 p = new ACOLevel7(g,start,finish);
/* instance variables */
     protected String[] names = g.getNames();
     protected boolean[] Edges;
     private static String istart;
     private static String idestination;
     private static int iAntSteps = idestination.length();
private static int iColonySize = 10000;
private static double iPheromoneStrength = 1.8d;
private static int iEvaporationSpan = 100;
private static double iEvaporationRate = 0.98d;
private boolean[][] graphEdges;
private Random iRandom = new Random();
/* constructor */
public ACOLevel7(myGraph g, String start, String finish) {
     Map map = new Map();
     istart = start;
     idestination = finish;
     graphEdges = g.getEdges();
     if(g.validStartAndFinish(istart,idestination)){
     double bestScore = -1;
     System.out.println("Level 7");
     System.out.println(">>> Here is your route planner! <<<");
     for (int i = 0; i < iColonySize; i++) {
     Ant ant = new Ant();
     ant.wander(map, iAntSteps);
     double score = calcScore(ant.getTrail());
     ant.dropPheromones(score);
     if (score > bestScore) {
     System.out.println(String.format(" %5d %s %4.2f", (new Object[]
     { new Integer(i), ant.print(), new Double(score) })));
     bestScore = score;
     (map).tick();
     System.out.println("\n>>> finished <<<");
     else {
          System.out.println("\n>>> start or finish not in names array<<<");
double calcScore(AntTrail trail) {
double score = 0;
for (int i = 1; i <= iAntSteps; i++);
//      Gets the next Node to travel to
I NEED HELP HERE!!
     String String = idestination.substring(i - 1);
return (score / 55d) * iPheromoneStrength;
private class Map {
/* instance variables */
HashMap Map = new HashMap();
Location iStart = new Location();
/* constructor */
public Map() {
Map.put(iStart.getKey(), iStart);
public Location start() {
return iStart;
public ArrayList to(Location fromHere) {
// generate every vertex location that is valid from here
ArrayList newLocations = new ArrayList();
for (int i = 0; i < istart.length(); i++) {
Location n = new Location(fromHere,
String.valueOf(istart.String(i)));
if (!Map.containsKey(n.getKey()))
Map.put(n.getKey(), n); // add to the map
else
n = (Location)Map.get(n.getKey()); // existing location
newLocations.add(n);
return newLocations;
public void tick() {
Iterator i = Map.entrySet().iterator();
while (i.hasNext())
if (((Location)((java.util.Map.Entry)i.next()).getValue())
.evaporate())
i.remove();
private class Location {
private String iKey;
private String iname;
private double iPheromones = 1;
private int iEvaporation = iEvaporationSpan;
/* constructor: start location */
public Location() { istartt = ""; }
/* constructor: from another location */
public Location(Location from, String names) {
iKey = from.getKey() + "|" + names;
istartt = names;
public String getKey() {
return iKey;
public String getName() {
return istartt;
//public String getidestt(){
public void dropPheromones(double d) {
iPheromones += d;
iEvaporation = iEvaporationSpan; // reset the evaporation counter
public double getPheromones() {
return iPheromones;
public boolean evaporate() {
iPheromones = iPheromones * iEvaporationRate;
return --iEvaporation == 0;
private class Ant {
private AntTrail iTrail = new AntTrail();
public void wander(Map map, int steps) {
iTrail.addStep(map.iname());
for (int i = 0; i < steps; i++)
step(map);
private void step(Map map) {
ArrayList choices =map.to(iTrail.current());
Location next = null;
double span;
// sum the available span
span = 0;
Iterator i1 = choices.iterator();
while (i1.hasNext())
span = span + ((Location)i1.next()).getPheromones();
// choose an index value
double index = iRandom.nextDouble() * span;
// find the location within the span with this index
span = 0;
Iterator i2 = choices.iterator();
while (i2.hasNext()) {
next = (Location)i2.next();
span = span + next.getPheromones();
if (index < span) break;
// add the chosen location to the trail
iTrail.addStep(next);
public AntTrail getTrail() {
return iTrail;
public void dropPheromones(double score) {
iTrail.dropPheromones(score);
public String print() {
return iTrail.print();
private class AntTrail {
private ArrayList iTrail = new ArrayList();
public void addStep(Location n) {
iTrail.add(n);
public Location getStep(int index) {
return (Location)iTrail.get(index);
public Location current() {
return getStep(iTrail.size() - 1);
public void dropPheromones(double score) {
Iterator i = iTrail.iterator();
while (i.hasNext())
((Location)i.next()).dropPheromones(score);
public String print() {
String s1 = "";
Iterator i = iTrail.iterator();
while (i.hasNext()) {
String s2 = ((Location)i.next()).getName();
if (!s1.equals("") && !s2.equals("")) s1 += "-";
s1 += s2;
return s1;
}

Presumably the thing that you want to do is to choose a path from a small number of alternatives based on some continually changing probability distribution (based on your Phermone strength)
Consider the simple case, where you choose between two paths, one with weight 17 and one with weight 5.
You sum the two weights, T = 17+5 = 22
You generate a random number between 1 and 22
and if it is less than 17 you choose the first path and if it is greater you choose the other path. Given the uniform distribution of your random numbers you have choosen the first path 17/22nds of the time.
In more general terms, without integer weights
You have a collection of n weights, Wi, you total them, T
You choose a random number, R, between zero and T (i.e. choose a random number between 0 and 1 and multiply by T) This effectively normalizes your distribution.
Then you subtract W1 from R. If the result went below zero your value was less than W1 so you take path1, if not, subtract W2 from R (R has already been reduced by W1 so what you are testing is whether your original random number was between W1 and W2) if it goes below zero take path 2, ...
Go through the weights in order until you get a result below zero.
This is the classical algorithm to select an alternative from a small number of possible alternatives where each alternative has a known probability of being selected.
I hope that helped. I did not actually read your code to see what you are doing, I just looked at the comment prior to the I NEED HELP HERE and made a guess as to what your problem was.
In the future, you will be more likely to get help quickly if you summarize your problem rather than just posting a wad of unreadable code.
So if I answered your question, your welcome, if not, well perhaps you can take a little more effort to explain your problem so that we don't have to work so hard to figure out what you want.
I am assuming that you know about the Random class and actually know how to generate simple random numbers. You see, you really didn't tell us what your problem is and where you need help, and thus force us to make assumptions.

Similar Messages

  • Query for finding shortest path

    I know nothing about Oracle Spatial. Just want to know if this query is possible using Spatial.
    Given the following data for undirected weighted graph,
    v1: vertex 1
    v2: vertex 2
    w: weight between vertices v1 and v2(or, distance of edge)
    table name : wgraph
    v1  v2  w
    k   a    2
    m  a    3
    k   c    1
    k   d    4
    c   b    2
    h   d    3
    c   h    3
    h   e    4
    e   b    4
    m  b    6Can I make a query which gives the shortest path from vertex 'a' to vertext 'e' using Spatial?
    If this possible, that query gives the following result. (row-spanning form)
    I think this is almost impossible using just a hierachical query.
    Any method for this in Oracle Spatial?
    spath
    a
    k
    c
    b
    e
    This is not a sort of homework or exam, just my interest.
    Thx in advance.
    Query Your Dream & Future at
    http://www.soqool.com

    yes why not! in your case just create a logical network- called LRS Network and insert your vertices in node- table and additional information plus cost in the link table.
    you can find ways using by dijkstra and A*

  • Need a help for finding best online tutorial site

    Could you please post some best PLSQL online tutorial site .
    Advance thanks to all of you.

    Please check this site
    Always good to refer oracle official site for reference.
    http://docs.oracle.com/cd/E11882_01/server.112/e26088/toc.htm
    ~Lokanath

  • Who has a find Open Path plug-in for CS4 Illustrator on WinXP and a close path also?

    Can anyone lead me to a plug-ins for finding open paths and closing them in CS4 on WinXP?
    Thanks

    Just a thought, but, have you tried using Live Paint?

  • BGB Best path selection

    Hi,
    Could someone tell me why second path remains as best?
    MPLS_CORE#show ip bgp 192.168.1.0
    BGP routing table entry for 192.168.1.0/24, version 27
    Paths: (2 available, best #2, table default)
      Advertised to update-groups:
         1         
      Refresh Epoch 1
      64513
        2.2.2.1 from 2.2.2.1 (10.201.240.2)
          Origin incomplete, metric 156160, localpref 100, valid, external
          rx pathid: 0, tx pathid: 0
      Refresh Epoch 1
      64512
        1.1.1.1 from 1.1.1.1 (192.168.4.253)
          Origin incomplete, metric 1415680, localpref 100, valid, external, best
          rx pathid: 0, tx pathid: 0x0
    Regards
    Michal 

    Hi Michal,
    Please refer below CCO document for BGP best path selection criteria on cisco routers
    http://www.cisco.com/c/en/us/support/docs/ip/border-gateway-protocol-bgp/13753-25.html
    If everything attribute is same then it comes to router-id and lowest router-id is preferred.
    11. Prefer the route that comes from the BGP router with the lowest router ID.
    The router ID is the highest IP address on the router, with preference given to loopback addresses. Also, you can use the bgp router-id command to manually set the router ID.
    In your case, second route is having lowest router-id (1.1.1.1)
    --Pls dont forget to rate helpful posts--
    Regards,
    Akash

  • What is the best Path for a J2EE developer with oracle?

    Hi,
    I am a J2EE developer, for the time being I work at a Commercial Bank as an enterprise application developer. I have learnt java when I was following a local IT diploma and with the help of books, works at my working place and the internet , today I am developing J2EE applications with JSP,Servlets,JSF2.0,EJB3.0 and third party JSF libraries etc. (I am also developing softwares using other programing languages such as Asp.net, C#.net, WPF etc, but I prefer to be in the java path). Other than that, I'm also working as the UI designer of most of our applications.
    I have those skills and practice after working for 4 years as a web/enterprise application developer & a UI designer, but now I have to focus on some paper qualifications and hence I am doing BCS.
    Now I want to be a java professional in Oracle's path, and I need to know what is the best path I can select to move with Oracle. I finished my classes of SCJP , but didn't do the exams as there were some rumors that Oracle will dump those exams in the future. I am interested in Oracle university, but I am unable to even think about it as I live in Sri Lanka and don't have that much of financial wealth to go USA and join.
    So I really appreciate if any Oracle professional could suggest me the best educational path according to what I mentioned about my technical and career background. Because I have a dream to join Oracle one day as an employee and being a good contributer to the same forum, which I am getting helps today!
    Thanks!!!

    As you can see on our website, Oracle did not retire the Java certifications. You can browse through the available certifications and hopefully help to determine your path.
    http://education.oracle.com/pls/web_prod-plq-dad/db_pages.getpage?page_id=140
    SCJP has now become Oracle Certified Professional Java Programmer. You can find more info on those exams on our website here: http://education.oracle.com/pls/web_prod-plq-dad/db_pages.getpage?page_id=320.
    Regarding training, perhaps live virtual training would be an option for you. You can find more information at http://education.oracle.com/pls/web_prod-plq-dad/db_pages.getpage?page_id=233.
    Regards,
    Brandye Barrington
    Certification Forum Moderator

  • DPM encountered an error while performing an operation for \\?\Volume{fc1f0549-9865-4349-b4df-8596a19ad7fe}\FolderPath\Work\ on FileServer (ID 2033 Details: The system cannot find the path specified (0x80070003))

    DPM encountered an error while performing an operation for \\?\Volume{fc1f0549-9865-4349-b4df-8596a19ad7fe}\FolderPath\Work\ on FileServer (ID 2033 Details: The system cannot find the path specified (0x80070003))
    Can I know what this mean? It completely fail all entire job.
    Backup was on half way go, it already took about 3TB data and it fail.

    Hi Oneoa,
    Please verify the antivirus exeptions. Look at this two links for more information:
    http://technet.microsoft.com/en-us/library/ff399439.aspx
    http://support.microsoft.com/kb/928840
    I hope this solves your problem, please post your progress so I may assist you further.
    Best Regards
    Robert Hedblom
    MVP DPM
    Check out my DPM blog @ http://robertanddpm.blogspot.com

  • Graphs, finding shortest Path using BFS

    COuld some one give me some lead on how to go about finding shortest path between two nodes on a graph using BFS, Edges are labeled but not weighted. What kind of modification will be need to BFS for this?

    http://en.wikipedia.org/wiki/Breadth-first_search

  • Cannot find real path for '/var/install/Client/DATA_UNITS/HDB_CLIENT_LINUX_X86_64/../install/sdbrun': No such file or directory

    Hi Experts,
    I got the error "cannot find real path for '/var/install/Client/DATA_UNITS/HDB_CLIENT_LINUX_X86_64/../install/sdbrun': No such file or directory" and "Error during execution of HdbCmdClazz section!" during SAP NW 740 HANA installation. I specified the right path for HDB client (see in attachment).
    Any ideas, please?
    Thanks & best regards,
    Sreenu

    The service file is in $srcdir, not $_svnmod/builders/cmake.
    You're using an outdated PKGBUILD template too. The svn source should be included in the source array and not checked out manually during the build process.
    EDIT: since this repository requires authentication, perhaps the correct format won't work.
    Last edited by WorMzy (2015-02-08 23:07:59)

  • The save for the web function has stopped working in my copy of photoshop elements 12.  I get this message, " The operation could not be completed.  The system cannot find the path specified" Resetting preferences did not fix.

    The save for the web function has stopped working in my copy of photoshop elements 12.  I get this message, “ The operation could not be completed.  The system cannot find the path specified” Resetting preferences did not fix.

    my os is windows 7.  elements 12 worked fine for many months then save for the web stopped working

  • When i do file, save for web, i get an error that says " the operation could not be completed. The system cannot find the path specified." What can fix this?

    when i finish a file and try to "save for web", i get an error box saying The operation cannot be completed. The system cannot find the path Specified.
    What can i do or where do i look?

    ELEMENTS 12 AND ELEMENTS 13
    Upgraded to 13 Thinking might resolve the issue.
    Was working fine up until we had "Tech" come in the office and "up grade some stuff"
    then all of a sudden i started getting this message, something happened but i don't have a clue what.

  • I can't find the path in SPRO for a configuration table

    Dear all,
    I am currently doing some configuration in SPRO and I need to document it in an Excel file.
    My configuation is for Plant Maintenance (PM) and I need some help finding the path through SPRO in which I can find the table T370FLD_STN.
    I have already tried the simple stuff like:
    Control+F and tried to find the name of the table - No Results
    I also went through  SE16N and clicked F1 and then in the key symbol - No results.
    I really need help FINDING THE PATH IN SPRO. That's my goal.
    Thanks to you all,
    Manuel

    Hello
    I have just tested on my system and I got the following SPRO path:
    - Plant Maintenance and Customer Service
    - Master Data in Plant Maintenance and Customer Service
    - Technical Objects
    - Settings for Fleet Management
    - Consumption-Relevant Counter Reading Update
    - Create Gas Station
    I can't tell why this procedure did not work on your system. Did you receive a popup to select the customizing project when you clicked the customizing button? I got a popup and I choose the option "continue w/o specifying a project".
    BR
    Caetano

  • Version 2014.1.0 - save for web returns error: the system cannot find the path specified. Help?

    I'm on PC (yah, yah, I know)
    When I click "save for web" I get the following error:
    The operation could not be completed.
    The system cannot find the path specified.
    I thought I could repair Photoshop, but the 2014 version doesn't seem to have that option in the control panel's Programs and Features - only uninstall. The Cloud doesn't seem to have a "reinstall" option that I can see.I'd hate to have to redownload the whole thing and start over, but I suppose I may have to.
    Any ideas?

    I'm on PC (yah, yah, I know)
    When I click "save for web" I get the following error:
    The operation could not be completed.
    The system cannot find the path specified.
    I thought I could repair Photoshop, but the 2014 version doesn't seem to have that option in the control panel's Programs and Features - only uninstall. The Cloud doesn't seem to have a "reinstall" option that I can see.I'd hate to have to redownload the whole thing and start over, but I suppose I may have to.
    Any ideas?

  • What's the best approach/program for finding and eliminating duplicate photos on my hard drive?

    What's the best approach/program for finding and eliminating duplicate photos on my hard drive? I have a "somewhat" older version of iPhoto (5.0.4), and it doesn't seem to offer anything like that except during the importing phase of syncing my phone...

    I wonder, is there room to transfer them to your phone, & then back to filter them?

  • Need FM to find physical path for given logical path

    Hi Guru's,
    I wanted to find the physical path for the given the logical path.
    I have a requirement where i have to write records into the file  mentioned via logical path .Inside the program i wanted to fetch the physical path for given logical path .
    Is there any FM to achieve this functionality.
    Thanks!!
    Pravee

    Use fm FILE_GET_NAME to get physical file name from a logical file name. But u have to maintain the mapping between logical file name and physical file name in tran. FILE.
         call function 'FILE_GET_NAME'
              exporting
                   logical_filename = lds_name << Logical file name
              importing
                   file_name        = ds_name << Physical file name
              exceptions
                   file_not_found   = 01.
    Regards,
    Joy.

Maybe you are looking for

  • 6th gen nano not recognized by win7, nor itunes

    i've been using my 6th gen nano for a few months now with no problems. suddenly today, i plugged it in and it wasn't recognized by windows and doesn't show up in itunes. i keep getting errors stating the unknown device is not recognized. i've uninsta

  • Shared services security  problem

    Hi All, My security is in Shred services mode When i open Shared services In the ApplicationGroup Folders In the APS servers I remove my Essbase server now i want to add it again please can any one tell me how can i add it what should i do to get tha

  • Why don't my adjustments in LR4 show up when I edit in Photoshop CS5?

    Why is it when I edit an image in lightroom 4 then go to retouch etc in photoshop cs5 those adjustements that I made on the image in lightroom ie contrast, saturation, exposure etc don't show up when I move the raw image into photoshop to do final re

  • No IDOCs on monitor after an upgrade

    Basis guys have done an upgrade in qas and now when I try to reprocess an existing idoc with the TC we19 with status 03 (founded in we02) I cant see anything in the sxi_monitor. When I go to SM58 in R3, it appears: IDOC_INBOUND_ASYNCHRONOUS "IDoc ada

  • Safe to Erase External Boot Volume?

    Naive question, I guess: I have one partition on my LaCie external FireWire drive currently set up as a boot volume (cloned as a Sandbox with shared users and apps. with SuperDuper from Mac HD). Is it safe to use DiskUtility to erase this partition,