2012年8月23日 星期四

PSO粒子群演算法的問題設定


原本的程式預設是找最小值,程式碼如下(PBmain.java)
  //判定改變pgbest
    void check(double now_answer, double pbest_answer, double gbest_answer, int now_bird, int bird_var_num, double[][] bird_x, double[] bird_temp_now, double[][] pbest, double[] bird_temp_pbest, double[] gbest, double[] bird_temp_gbest) {
   
        int i = now_bird, j;
       
        //結果較好就轉存pbest
        if ( now_answer< pbest_answer ) {
            for (j=0; j< bird_var_num; j++ ) {
            //維度變化
                
                pbest[i][j] = bird_temp_now[j];
            } //end for
               
            //結果較好就轉存gbest
            if  ( now_answer< gbest_answer ) {
                for (j=0; j< bird_var_num; j++ ) gbest[j] = bird_temp_now[j];
            } //end if
        } end if
    } //end check()

將小於符號改成>大於符號應該就是找最大值了
此外,該PSO演算法程式可以自訂問題q1v2.txt,問題的定義如下


//問題定義開始 user_function
package myPackage.javaclass;public class user_function{
    public static int v=2; //變數的個數
    //function 開始
    public double function(double[] x){
        //z為目標值
        double z = 35*x[0]+25*x[1];
       
       //輸入限制式,符合限制式條件者才傳會目標值z,否則傳回一個大值
 if ((0.32*x[0] + 0.22*x[1] >= 8) & (0.11*x[0] + 0.09*x[1] >= 3) & (0.15*x[0]+0.10*x[1] >= 4))
 {
         return z;
 }else
 {
  z = 1.79769E+308;
  return z;
 }// end of if else
 }// end of public double function 問題定義結束
}//end of user_function

2012年8月10日 星期五

我一直很喜歡相機的廣告,這些相機大廠的廣告不但畫面好,選歌更是厲害,以下是Nikon
I AM NIKON CINEMA AD


Sleep don't visit, so I choke on sun
 And the days blur into one
 And the backs of my eyes hum with things
I've never done
 Sheets are swaying from an old clothesline
 Like a row of captured ghosts over old dead grass
 Was never much but we made the most
 Welcome home
 Ships are launching from my chest
 Some have names but most do not
 If you find one, please let me know what piece
I've lost Heal the scars from off my back
 I don't need them anymore
 You can throw them out or keep them in your mason jars I've come home
 All my nightmares escaped my head
 Bar the door, please don't let them in
 You were never supposed to leave
 Now my head's splitting at the seams
 And I don't know if I can Here, beneath my lungs,
I feel your thumbs press into my skin again






同樣的canon也有廣告歌
http://www.youtube.com/watch?v=sQ7n_KLZeCk




2012年8月4日 星期六

java找不到package的問題classpath

最近在研究粒子群演算法,很高興有老師(尹邦嚴教授)及他實驗室的研究團隊分享了他的研究,使用了java做成的粒子群演算法案例並分享程式碼(http://intelligence.im.ncnu.edu.tw/demo/psodemo/),可是發現在我自己的電腦嘗試時又發現以前我在做multiAgent多代理人程式時所發生的問題,問題應該是找不到package,經過努力google,發現應該是classpath的問題,

我重新檢視目前classpath的設定,使用set classpath可以看到原來目前只找c:\program files\java\jak1.7.0\lib,所以趕緊修改環境變數


把classpath前面加上目前的路徑,也就是  .;  ,設定好後重新開機

重新開機後總算成功編譯,產生PSO的畫面,再次感謝尹老師及其研究團隊。

安裝JVM java虛擬機器

常常有機會在網頁上執行java applet的程式,發現瀏覽器出現類似找不到圖的畫面
如果確定該網頁是執行java applet的程式,接著應該檢查控制台,如果沒有java的圖案,很明顯就是沒有安裝JVM(java虛擬機器)


接著當然按下免費java下載



安裝完後重新檢查控制台會發現多了一個圖示
重新檢視之前同一個網頁,終於出現我們希望看到的內容