Artificial Intelligence - هوش مصنوعی

Artificial Intelligence - هوش مصنوعی (http://artificial.ir/intelligence/)
-   الگوریتم کلونی مورچگان (Ant Colony Algorithm) (http://artificial.ir/intelligence/forum25.html)
-   -   دانلود کد الگوریتم بهینه سازی کلونی مورچه ها برای حل مسأله فروشنده دوره گرد (http://artificial.ir/intelligence/thread351.html)

fandogh2011 ۰۸-۱۸-۱۳۹۰ ۱۲:۴۵ قبل از ظهر

سلام. من میخوام مقالهای در خصوص پیدا کردن کوتاهترین مسیر درشبکه توسط الگوریتم کلونی مورچه بنویسم لطفا راهنمایم کنید اگه پروژه یا مقاله ای در این خصوص هست واسم بذارید.ممنون از لطفه دوستان

en_ahmad ۰۸-۱۸-۱۳۹۰ ۰۳:۱۲ قبل از ظهر

نقل قول:

نوشته اصلي بوسيله fandogh2011 (پست 21029)
سلام. من میخوام مقالهای در خصوص پیدا کردن کوتاهترین مسیر درشبکه توسط الگوریتم کلونی مورچه بنویسم لطفا راهنمایم کنید اگه پروژه یا مقاله ای در این خصوص هست واسم بذارید.ممنون از لطفه دوستان

سلام
لطفا به پست زیر یه سری بزنید. :3:

Artificial Intelligence - هوش مصنوعی - نمايش پست تنها - ليست تمام مقالات فارسی الگوريتم کلوني مورچه ها

در ضمن در اولین صفحه این تاپیک هم یکسری کد تو این زمینه قرار داده شده.

ayfer.a11 ۰۸-۱۸-۱۳۹۰ ۰۳:۱۳ قبل از ظهر

2(ها)ضميمه
نقل قول:

نوشته اصلي بوسيله fandogh2011 (پست 21029)
سلام. من میخوام مقالهای در خصوص پیدا کردن کوتاهترین مسیر درشبکه توسط الگوریتم کلونی مورچه بنویسم لطفا راهنمایم کنید اگه پروژه یا مقاله ای در این خصوص هست واسم بذارید.ممنون از لطفه دوستان

سلام
---
Ant Colony Optimization and its Application to
Adaptive Routing in Telecommunication Networks


A Position Based Ant Colony Routing
Algorithm for Mobile Ad-hoc Networks

mahshidmr64 ۱۲-۵-۱۳۹۰ ۰۳:۵۴ بعد از ظهر

سلام میشه مقاله انگلیسی ای که از روی اون کد الگوریتم بهینه سازی کلونی مورچه ها برای حل مسأله فروشنده دوره گرد رو پیاده سازی کردید هم روی سایت بگذارید یا اسمش رو بگید؟

luckygirl ۱۲-۶-۱۳۹۰ ۰۹:۵۴ بعد از ظهر

2(ها)ضميمه
سلام
من کد اول رو از سایت متلب و کد دوم رو از سایت eca گرفتم
امیدوارم براتون مفید باشه
موفق باشید

lo0ol ۱۲-۷-۱۳۹۰ ۰۶:۳۲ بعد از ظهر

نقل قول:

نوشته اصلي بوسيله Reyhane (پست 3736)
كد:

import java.applet.*;
import java.util.*;
import java.awt.*;
import java.net.*;
import java.io.*;

public class TSP extends Applet implements Runnable {

        public int        NCITY = 5;
        public int        NGEONEURON;
        public static final double        COUNTRY = 1.00;
        public static final double        NEAR = 0.05;
       
  public static final Color bkC = new Color(0x000090);       
  public static final Color bk2C = new Color(0x000050);       
  public static final Color lnC = new Color(0xff0000);       
  public static final Color ln2C = new Color(0xcccc00);       
  public static final Color fgC = new Color(0xffffff);       

        public Image  homeI,offscreen;
  public int imagewidth ,imageheight;
        public Thread  animator    = null;
        public boolean please_stop = false;
        Font mF = new Font("Courier", Font.BOLD, 12);
        Font sF = new Font("Courier", Font.BOLD, 8);
  public int counter;
       
        public City city[];
        public geoNeuron gn[];
       
        public double r[][];
       
        public double theta, phi, momentum;
       
        public Scrollbar cscroll;

    ///////////////////////////////////////////////////////////////////
    //
    //  Init section
    //
    ///////////////////////////////////////////////////////////////////

                public void kohonenInit(){
                        theta = 0.5;
            phi  = 0.5;
            momentum = 0.995;

                        NCITY = cscroll.getValue()/10;
                        NGEONEURON = NCITY*2;
                       
                  //URL url;       
      //homeI = this.getImage(this.getDocumentBase(), "home.gif");
       
      city = new City[NCITY];
      for(int i = 0; i<NCITY; i++) city[i] = new City(Math.random()*COUNTRY, Math.random()*COUNTRY);
     
      double alpha = 0.0;     
      gn = new geoNeuron[NGEONEURON];
      for(int i = 0; i<NGEONEURON; i++){
        gn[i] = new geoNeuron(0.5+0.5*Math.cos(alpha),0.5+0.5*Math.sin(alpha));
        alpha += Math.PI *2.0 / (double)(NGEONEURON);
      }
     
      r = new double[NGEONEURON][NGEONEURON];
     
      makeR(theta);       

                        counter = 0;
               
                }

    ///////////////////////////////////////////////////////////////////
    //
    //  Problem section
    //
    ///////////////////////////////////////////////////////////////////

                public void makeR(double th){
                //System.out.println("");
      for(int i=0; i<NGEONEURON; i++){
              r[i][i]= 1.0;
              for(int j=i+1; j<NGEONEURON; j++){
                      r[i][j] = Math.exp( -1.0 * ( gn[i].dist(gn[j])*gn[i].dist(gn[j]) )/(2.0*th*th));
                      r[j][i] = r[i][j];
                            //System.out.print(" "+r[i][j]);
              }
              //System.out.println("");
      }
                }

    // The body of the animator thread.
    public void run() {
            int idx,j;
            double x1,x2,mindist;
            int count = 0;
        while(!please_stop) {
           
            counter++;
           
            // CHOSE A RANDOM PATTERN
            idx = (int)(Math.random()*NCITY);
            x1 = city[idx].x+(Math.random()*NEAR)-NEAR/2;
            x2 = city[idx].y+(Math.random()*NEAR)-NEAR/2;
            city[idx].choose++;
         
            // SEARCH FOR MINIMAL
            mindist = 100000.0;
            j = -1;
            for(int i=0; i<NGEONEURON;i++){
                    double d = (x1 - gn[i].wx)*(x1 - gn[i].wx) + (x2 - gn[i].wy)*(x2 - gn[i].wy);
                    //double d = x1*gn[i].wx + x2*gn[i].wy;
                    //System.out.println("d="+d);
                    if(d < mindist){
                            mindist = d;
                            j = i;
                    }
            }
                       
            gn[j].update++;
                   
            // UPDATE WEIGHTS
            for(int i=0; i<NGEONEURON;i++){
                    gn[i].wx += (phi * r[i][j] * (x1 - gn[i].wx));
                    gn[i].wy += (phi * r[i][j] * (x2 - gn[i].wy));
            }
                                             
            // DECREASE LEARNING PARAMETERS
            phi *= momentum;
            theta *= momentum;
           
            // RE-COMPUTE r MATRIX
                        makeR(theta);
                       
                       
                        // PLOT RESULT EVERY 10 SESSIONS
                        count = (count++)%10;
                       
                              if(count==0){
                                      //System.out.println("theta = "+theta+"  phi = "+phi);

                                                        paint(this.getGraphics());
           
                                                        // Call Garbage Collect
                                                        //System.gc();
                       
                    try {Thread.sleep(10);} catch (InterruptedException e){};
            }
        }
        animator = null;
    }
   
    ///////////////////////////////////////////////////////////////////
    //
    //  Functional section
    //
    ///////////////////////////////////////////////////////////////////
   
    public void init() {
   
            cscroll = new Scrollbar(Scrollbar.HORIZONTAL,NCITY*10, 10, 30, 200);
            cscroll.setLineIncrement(10);
            cscroll.setPageIncrement(10);
            add(cscroll);
           
            kohonenInit();       
    }

    private int toXReal(double val){int w = this.size().width;return (int)(val *((double)w/2.0-50.0) / COUNTRY +25.0);}
    private int toYReal(double val){int h = this.size().height;return (int)(val *((double)h-50.0) / COUNTRY +25.0);}
 
    private int to2XReal(double val){int w = this.size().width;return (int)((double)w/2.0 + val *((double)w/2.0-50.0) / COUNTRY +25.0);}
    private int to2YReal(double val){int h = this.size().height;return (int)(val *((double)h-50.0) / COUNTRY +25.0);}
   
    public void paintLeft(Graphics g) {
                        Dimension size = this.size();
                                                int w = size.width, h = size.height;
                                               
                                                g.setFont(mF);
                                               
                                                // CLEAR ALL
            g.setColor(bkC);
            g.fillRect(0, 0, w, h);
            // DRAW GRID
            g.setColor(bk2C);
            for(double i=0; i<=COUNTRY; i+=(COUNTRY/20.0)){
                    g.drawLine(toXReal(0.0),toYReal(i),toXReal(COUNTRY),toYReal(i));
                    g.drawLine(toXReal(i),toYReal(0.0),toXReal(i),toYReal(COUNTRY));
            }
           
            //DRAW PATH
            g.setColor(lnC);
            for(int i=0; i<NGEONEURON; i++){
                    g.drawLine( toXReal(gn[i].wx),toYReal(gn[i].wy),
                      toXReal(gn[(i+1)%NGEONEURON].wx),toYReal(gn[(i+1)%NGEONEURON].wy) );
                    g.drawString(""+i+"-"+(gn[i].update*100/counter)+"%",toXReal(gn[i].wx),toYReal(gn[i].wy));
            }

            g.setColor(fgC);
           
            // DRAW CITYS
            for(int i=0; i<NCITY; i++){
                    g.drawOval( toXReal(city[i].x)-4, toYReal(city[i].y)-4,8,8);
                    g.drawString(""+i+"-"+(city[i].choose*100/counter)+"%",toXReal(city[i].x),toYReal(city[i].y)+8);
            }
          }   
                public void paintRight(Graphics g) {
                        Dimension size = this.size();
                                                int w = size.width, h = size.height;
       
                                                // CLEAR ALL
            g.setColor(bkC);
            g.fillRect(0, 0, w, h);

                                                g.setFont(sF);

            // DRAW CITYS
            g.setColor(fgC);
            for(int i=0; i<NCITY; i++){
                    g.drawOval( to2XReal(city[i].x)-4, to2YReal(city[i].y)-4,8,8);
                    //g.drawString("["+city[i].wx+";"+gn[i].wy+"]",to2XReal(gn[i].x),to2YReal(gn[i].y));
            }
         
            g.setColor(ln2C);
            for(int i=0; i<NGEONEURON; i++)
                                      for(int j=i+1; j<NGEONEURON; j++){
                                              g.drawLine( to2XReal(gn[i].x),to2YReal(gn[i].y),
                                  to2XReal(gn[j].x),to2YReal(gn[j].y));
                                        g.drawString(""+r[i][j],to2XReal((gn[i].x+gn[j].x)/2),to2YReal((gn[i].y+gn[j].y)/2));
                                              //r[i][j] = Math.exp( -1.0 * (double)( gn[i].dist(gn[j])*gn[i].dist(gn[j]) )/(2.0*th));
                                             
                                      }
                                                g.setFont(mF);
            g.setColor(fgC);
                              g.drawString("phi="+phi+" theta="+theta,to2XReal(0.0),to2YReal(0.0)+20);
    }   

    public void paint(Graphics g) {
                        Dimension size = this.size();
                                                int w = size.width, h = size.height;
                                               
                                                this.setBackground(bkC);

                                               
                                                if ((offscreen == null) || ((imagewidth != w) || (imageheight != h))) {
                offscreen = this.createImage(w, h);
                imagewidth = w;
                imageheight = h;
            }
                                               
                                                Rectangle clip = new Rectangle(toXReal(0),toYReal(0),toXReal(COUNTRY),toYReal(COUNTRY));
                                                                                               
                                                Graphics goff = offscreen.getGraphics();
                                                goff.clipRect(clip.x, clip.y, clip.width, clip.height);
            Graphics g1 = this.getGraphics();
                                                g1.clipRect(clip.x, clip.y, clip.width, clip.height);
                                               
            paintLeft(goff);
            g1.drawImage(offscreen, 0, 0, this);
           
                                                //clip = new Rectangle(to2XReal(0),to2YReal(0),to2XReal(COUNTRY),to2YReal(COUNTRY));
                                                           
                                          //goff = offscreen.getGraphics();
                                                //goff.clipRect(clip.x, clip.y, clip.width, clip.height);
            //g1 = this.getGraphics();
                                                //g1.clipRect(clip.x, clip.y, clip.width, clip.height);
                                               
            //paintRight(goff);
            //g1.drawImage(offscreen, 0, 0, this);
           
            clip = null;
            goff = null;
            g1 = null;
            System.gc();
           
            // CLEAR ALL
            g.setColor(bkC);
            g.fillRect(w/2+30,0,w/2+130, 20);
            g.setColor(fgC);

            g.drawString("# of city:"+cscroll.getValue()/10,w/2+30,20);

    }
 
    // Start the animation
    public void start() {
        animator = new Thread(this);
       
        animator.start();
       
    }
    // Stop it.
    public void stop() {
        if (animator != null) animator.stop();
        animator = null;
    }
   
    // Stop and start animating on mouse clicks.
    public boolean mouseDown(Event e, int x, int y) {
    // if running, stop it.  Otherwise, start it.
      if (animator != null){
              please_stop = true;
      }else{
              please_stop = false;
                                animator = new Thread(this);
                               
                                kohonenInit();
        animator.start();
      }
      return true;
    }

}


سلام.بابت کد ممنون.
ولی کد رو ناقص گذاشتید!!! :39:
کلاس های geoNeuron و City رو جا انداختید. :112:
كد:

public class City{
       
        public double x,y;
        public int update,choose;
       
        public City(double x,double y){
                this.x = x;
                this.y = y;
                               
                update = 0;
                choose = 0;
               
        }
       
        public double dist(City c){
                double dx = this.x - c.x;
                double dy = this.y - c.y;
               
                return Math.sqrt(dx*dx + dy*dy);
               
        }
       
}

كد:

public class geoNeuron{
       
        public double x,y;
        public double wx,wy;
        public int update,choose;
       
        public geoNeuron(double x,double y){
                this.x = x;
                this.y = y;
               
                this.wx = Math.random();
                this.wy = Math.random();
               
                update = 0;
                choose = 0;
               
        }
       
        public double dist(geoNeuron c){
                double dx = this.x - c.x;
                double dy = this.y - c.y;
               
                return Math.sqrt(dx*dx + dy*dy);
               
        }
       
        public double wdist(geoNeuron c){
                double dx = this.wx - c.wx;
                double dy = this.wy - c.wy;
               
                return Math.sqrt(dx*dx + dy*dy);
               
        }

}

موفق باشید.

luckygirl ۱۲-۷-۱۳۹۰ ۱۱:۳۸ بعد از ظهر

مرسی بخاطر توجه و تذکرتون...

hamid.enrique ۰۱-۲۳-۱۳۹۱ ۰۵:۱۸ بعد از ظهر

سلام
من یه فایل pdf ya ppt در مورد پیاده سازی الگوریتم بهینه سازی کولونی مورچه ها میخوام که یا چند روش رو با هم مقایسه کنه یا روی یه plant الگوریتم کلونی مورچه هارو پیاده سازی کنه
اگه کمکم کنید ممنون میشم

شریار ۰۳-۱۷-۱۳۹۲ ۰۷:۵۹ بعد از ظهر

[salam ye poroje mikham dar morede hoshe masnoei va foroshandey doregard va koloni morchegan mammon misham age komakam konid .ba sepase faravan

ZOHRE.MO ۰۴-۱۹-۱۳۹۲ ۱۰:۱۹ قبل از ظهر

سلام بچه ها میشه یه مقاله درباره الگوریتم کلونی مورچه ها البته انگلیسی واسه من بفرستید ممنون


زمان محلي شما با تنظيم GMT +3.5 هم اکنون ۰۳:۰۹ قبل از ظهر ميباشد.

Powered by vBulletin® Version 3.8.3
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.1.0 ©2007, Crawlability, Inc.