Artificial Intelligence - هوش مصنوعی  
انجمن را در گوگل محبوب کنيد :

بازگشت   Artificial Intelligence - هوش مصنوعی > الگوریتم ها > الگوریتم کلونی مورچگان (Ant Colony Algorithm)


 
تبليغات سايت
Iranian Association for the Advancement of Artificial Intelligence
ارسال تاپيک جديد  پاسخ
 
LinkBack ابزارهاي تاپيک نحوه نمايش
قديمي ۰۶-۳۱-۱۳۸۸, ۰۶:۴۰ قبل از ظهر   #1 (لینک دائم)
Administrator
 
آواتار Astaraki
 
تاريخ عضويت: خرداد ۱۳۸۷
محل سكونت: تهران-کرج!
پست ها: 3,465
تشكرها: 754
16,337 تشكر در 3,127 پست
My Mood: Mehrabon
ارسال پيغام Yahoo به Astaraki
Wink دانلود کد الگوریتم بهینه سازی کلونی مورچه ها برای حل مسأله فروشنده دوره گرد

الگوریتم بهینه سازی کلونی مورچه ها، و یا به اختصار الگوریتم مورچه ها، از رفتار مورچه های طبیعی که در مجموعه ها بزرگ در کنار هم زندگی می کنند الهام گرفته شده است و یکی از الگوریتم های بسیار کارآمد در حل مسائل بهینه سازی ترکیبی است. الگوریتم های دیگری نیز بر اساس الگوریتم مورچه ها ساخته شده اند که همگی سیستم های چند عاملی هستند و عامل ها مورچه های مصنوعی یا به اختصار مورچه هایی هستند که مشابه با مورچه های واقعی رفتار می کنند. الگوریتم مورچه ها، یک مثال بارز از هوش جمعی هستند که در آن عامل هایی که قابلیت چندان بالایی ندارند، در کنار هم و با همکاری یکدیگر می توانند نتایج بسیار خوبی به دست بیاورند. این الگوریتم برای حل و بررسی محدوده وسیعی از مسائل بهینه سازی به کار برده شده است. از این میان می توان به حل مسأله کلاسیک فروشنده دوره گرد و همچنین مسأله راهیابی در شبکه های مخابرات راه دور اشاره نمود.

مساله فروشنده دوره گرد (Traveling Salesman Problem) و یا به اختصار TSP، يكي از مسائل مشهور بهينه سازي تركيبي است. در این مسأله، يك فروشنده دوره گرد مي خواهد به چند شهر سفر کند و كالاي خود را به فروش برساند. اما می بایست از تمام شهرها عبور کند، از هر شهر فقط يك بار عبور كند و با طی کوتاه ترین مسير، سفر خود را به پایان برساند. حل این مساله کاربردهای وسیعی در حوزه های مختلف مهندسی دارد. از جمله مسائلی که از نظر ریاضی با مسأله TSP معادل هستند، می توان به حل انواع مسایل زمانبندی، مسیریابی، جایابی کالا در انبار، جایابی ماشینها در کارگاه ها، و طراحی مدارات چاپی اشاره نمود.

دانلود رایگان کد الگوریتم بهینه سازی کلونی مورچه ها برای حل مسأله فروشنده دوره گرد
فايل ضميمه
نوع فايل: zip aco_tsp.zip (69.1 كيلو بايت, 6521 نمايش)

ويرايش شده توسط Astaraki; ۰۷-۱-۱۳۸۸ در ساعت ۰۷:۳۰ قبل از ظهر
Astaraki آفلاين است   پاسخ با نقل قول
از Astaraki تشكر كرده اند:
*sepid* (۰۹-۱۱-۱۳۸۹), aragon1364 (۰۸-۱۳-۱۳۸۸), bluelithium (۰۷-۱۶-۱۳۸۸), donya (۰۸-۲۴-۱۳۹۰), e-eng (۱۱-۷-۱۳۸۹), elles (۰۹-۲۶-۱۳۹۲), green_Dream (۱۲-۲-۱۳۸۸), hamed.n53 (۰۸-۱۹-۱۳۹۳), hesam 1714 (۰۳-۲۶-۱۳۹۳), hoseynzade (۱۰-۲۱-۱۳۹۰), m0hammad_01 (۰۲-۲۲-۱۳۹۲), maer (۰۷-۱۷-۱۳۸۹), magma (۰۹-۲۹-۱۳۸۹), maryamm (۰۷-۱۵-۱۳۸۹), mehdinajafinia (۰۴-۲-۱۳۹۰), mohammadmono (۰۱-۲۹-۱۳۹۰), nasiry (۰۲-۱-۱۳۹۰), perennial (۰۳-۲۷-۱۳۹۰), sadegh3333 (۰۷-۲۱-۱۳۹۱), sadegh_anzan (۰۶-۱۷-۱۳۹۱), saeedm (۰۲-۲۰-۱۳۹۵), shr776 (۰۳-۱۷-۱۳۹۱), Solsal (۰۴-۱۲-۱۳۹۰), tayeb_compute (۰۳-۲۱-۱۳۹۱), محمد فرهنگ (۰۸-۱۱-۱۳۹۲), vahdat666 (۱۲-۶-۱۳۸۸), رانا (۰۸-۲۶-۱۳۸۸), سوسن خانوم (۰۷-۸-۱۳۸۹)

  #ADS
نشان دهنده تبلیغات
تبليغگر
 
 
 
تاريخ عضويت: -
محل سكونت: -
سن: 2010
پست ها: -
 

نشان دهنده تبلیغات is online  
قديمي ۱۰-۲۲-۱۳۸۸, ۰۸:۳۴ بعد از ظهر   #2 (لینک دائم)
عضو جدید
 
آواتار goodfriends
 
تاريخ عضويت: دي ۱۳۸۸
پست ها: 1
تشكرها: 0
0 تشكر در 0 پست
پيش فرض

با سلام خدمت دوستان عزیز:
میشه کد جاوای الگوریتم فروشنده ی دوره گرد رو که صد در صد اجرا بشه بزارید تو سایت

ممنون
goodfriends آفلاين است   پاسخ با نقل قول
قديمي ۱۰-۲۳-۱۳۸۸, ۰۸:۱۸ بعد از ظهر   #3 (لینک دائم)
Administrator
 
آواتار Astaraki
 
تاريخ عضويت: خرداد ۱۳۸۷
محل سكونت: تهران-کرج!
پست ها: 3,465
تشكرها: 754
16,337 تشكر در 3,127 پست
My Mood: Mehrabon
ارسال پيغام Yahoo به Astaraki
Arrow

نقل قول:
نوشته اصلي بوسيله goodfriends نمايش پست
با سلام خدمت دوستان عزیز:
میشه کد جاوای الگوریتم فروشنده ی دوره گرد رو که صد در صد اجرا بشه بزارید تو سایت

ممنون
كد:
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;
    }

}
Astaraki آفلاين است   پاسخ با نقل قول
از Astaraki تشكر كرده اند:
maer (۰۷-۱۷-۱۳۸۹), mehdinajafinia (۰۴-۲-۱۳۹۰), mohammadmono (۰۱-۲۹-۱۳۹۰), nasiry (۰۲-۱-۱۳۹۰), perennial (۰۳-۲۷-۱۳۹۰), sadegh3333 (۰۷-۲۱-۱۳۹۱), Solsal (۰۴-۱۲-۱۳۹۰)
قديمي ۱۲-۷-۱۳۹۰, ۰۶:۳۲ بعد از ظهر   #4 (لینک دائم)
عضو جدید
 
آواتار lo0ol
 
تاريخ عضويت: اسفند ۱۳۸۹
پست ها: 1
تشكرها: 1
2 تشكر در 1 پست
Thumbs up

نقل قول:
نوشته اصلي بوسيله Reyhane نمايش پست
كد:
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;
    }

}
سلام.بابت کد ممنون.
ولی کد رو ناقص گذاشتید!!!
کلاس های geoNeuron و City رو جا انداختید.
كد:
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);
		
	}

}
موفق باشید.
lo0ol آفلاين است   پاسخ با نقل قول
از lo0ol تشكر كرده اند:
hamed.n53 (۰۸-۱۹-۱۳۹۳), m0hammad_01 (۰۲-۲۲-۱۳۹۲)
قديمي ۱۲-۷-۱۳۹۰, ۱۱:۳۸ بعد از ظهر   #5 (لینک دائم)
عضو فعال
 
آواتار luckygirl
 
تاريخ عضويت: آبان ۱۳۸۹
پست ها: 16
تشكرها: 2
12 تشكر در 6 پست
My Mood: Mehrabon
پيش فرض

مرسی بخاطر توجه و تذکرتون...
luckygirl آفلاين است   پاسخ با نقل قول
قديمي ۰۵-۱۹-۱۳۸۹, ۱۰:۰۷ بعد از ظهر   #6 (لینک دائم)
عضو جدید
 
آواتار tavasoli
 
تاريخ عضويت: مرداد ۱۳۸۹
پست ها: 1
تشكرها: 0
0 تشكر در 0 پست
پيش فرض

می شه کد c++ حل مسئله فروشنده دوره گرد با استفاده از کلونی مورچه رو توی سایت بگذارین
tavasoli آفلاين است   پاسخ با نقل قول
قديمي ۰۶-۳۰-۱۳۸۹, ۰۷:۴۷ بعد از ظهر   #7 (لینک دائم)
عضو جدید
 
آواتار Gomnameh_AI
 
تاريخ عضويت: شهريور ۱۳۸۹
پست ها: 3
تشكرها: 0
1 تشكر در 1 پست
Lightbulb

سلام من یک پزوهش گر هستم روی تئوری خدم تکنولوژی PTT کار می کنم 2 تا از مقاله هام در موزد حل مسائل NP در حال بررسی که امیدوارم به زودی ACCEPT بگیرم. حالا دارم روی الگریتم مورچه و کوچ پرستو در PTT کار می کنم.
از اون جایی که من C++ کارم این کدا خیلی بدردم می خره از شما متشکرم. ممنون
کد C++ رو هم میشه گیر اورد؟
راستی دعوت به هم کاری می کنم eee.team.creator@gmail.com و برایه اطلا عات بیشتر در مورد PTT به eeeQuestions@gmail.comای میل بزنید. مرC.
Gomnameh_AI آفلاين است   پاسخ با نقل قول
قديمي ۰۶-۳۰-۱۳۸۹, ۰۷:۵۰ بعد از ظهر   #8 (لینک دائم)
عضو جدید
 
آواتار Gomnameh_AI
 
تاريخ عضويت: شهريور ۱۳۸۹
پست ها: 3
تشكرها: 0
1 تشكر در 1 پست
پيش فرض

راستی چند نوع الگریتم ازدهام هست؟
Gomnameh_AI آفلاين است   پاسخ با نقل قول
قديمي ۱۰-۵-۱۳۸۹, ۰۲:۰۱ بعد از ظهر   #9 (لینک دائم)
عضو جدید
 
آواتار magma
 
تاريخ عضويت: آبان ۱۳۸۹
محل سكونت: تهران
پست ها: 1
تشكرها: 4
0 تشكر در 0 پست
پيش فرض

سلام من یک پروژه ای دارم که باید کد اجرایی الگوریتم کوله پشتی یا فروشنده دوره گرد رو که توسط الگوریتم ژنتیک یا کلونی مورچه ها پیاده سازی شده رو ارائه بدم . ممنون میشم اگه کمکم کنید
magma آفلاين است   پاسخ با نقل قول
قديمي ۰۲-۱-۱۳۹۰, ۰۲:۵۰ بعد از ظهر   #10 (لینک دائم)
عضو جدید
 
آواتار nasiry
 
تاريخ عضويت: مهر ۱۳۸۹
پست ها: 7
تشكرها: 2
0 تشكر در 0 پست
پيش فرض

سلام کد c++ حل مسئله فروشنده دوره گرد با استفاده از کلونی مورچه رو نیاز دارم ممنون میشم اگه کمکم کنید
nasiry آفلاين است   پاسخ با نقل قول
پاسخ

Tags
کلونی،مورچه



كاربران در حال ديدن تاپيک: 1 (0 عضو و 1 مهمان)
 
ابزارهاي تاپيک
نحوه نمايش

قوانين ارسال
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is فعال
شکلکها فعال است
كد [IMG] فعال است
كدهاي HTML غير فعال است
Trackbacks are فعال
Pingbacks are فعال
Refbacks are فعال




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


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

Teach and Learn at Hexib | Sponsored by www.Syavash.com and Product In Review

استفاده از مطالب انجمن در سایر سایت ها، تنها با ذکر انجمن هوش مصنوعي به عنوان منبع و لینک مستقیم به خود مطلب مجاز است

Inactive Reminders By Icora Web Design