2012-02-10 53 views
3

我正在爲學生開發基於控制檯的個人日程安排策劃。我的目標是,應用程序將根據用戶當天可用的總時間,執行用戶想要執行的活動,然後分配時間片並以表格格式顯示它們。學生的個人日程安排策劃

分配的時間將取決於主題(更多時間分配給更重要的任務等)。

我正在爲我的第4個學期英格蘭做這個項目。

我已經開始研究算法,我的問題是,是否有任何這樣的算法(已經)可用?我在網上搜索,但我發現的規劃算法都是針對公交時刻表和其他的,但不是我正在尋找的。

+2

聽起來就像是[揹包問題]的變化(HTTP:// EN .wikipedia.org/wiki/Knapsack_problem) – mcfinnigan 2012-02-10 11:28:18

+1

@mcfinnigan:你應該把它作爲一個答案[關於如何解決它或Java實現的問題和資源的一些更多的細節] – amit 2012-02-10 11:37:11

+0

@mcfinnigan:你可以給一個縮寫揹包問題?因爲我在sophomoer年,所以沒有算法理論作爲課程,所以不幸我不能理解wikipedia – lucifer 2012-02-10 11:44:29

回答

6

按照amit的要求,這裏有一些資源。

就我所知,揹包問題是一個最大化問題。給定一組特定的有用性和重量的項目,您希望選擇最佳子集 - 即給定重量的「最佳」項目組合 - 您可以在揹包/揹包中攜帶的最大容量。例如,在殭屍入侵中,電鋸可能是一個非常有用的物品,但它體積龐大,體積龐大,所以它的用處可能超過它的體積。而刀也是有用的,但重量要少很多。如果您選擇了刀,您也可以選擇割炬,撬棍,乾糧和睡袋,而如果您選擇電鋸,則只有乾糧的空間。

您的特殊問題是嘗試將一組活動合併到一個固定時間段中。要做到這一點,你需要重量某些因素的活動,如

  • 期,在此期間他們可能一天
  • 其持續時間
  • 其可取到學生
  • 它們是否能夠在類似活動之前或之後立即安排 - 例如如果一個學生剛去健身房,他們不太可能想參加游泳訓練。

然後您需要爲這些不同因素提出一個加權算法,並使用該加權算法來決定如何選擇特定日期的活動;記住不同的人可能會有不同的偏好,你需要在你使用的權重中允許某種形式的可配置性。 (請注意,這是所有假設的基礎上我有限的接觸算法 - 正如我所說,我從來沒有這樣做過,我的第一個想法是如何處理這個問題)。

我通過谷歌發現的一些資源: http://www.es.ele.tue.nl/education/5MC10/Solutions/knapsack.pdf

http://mathworld.wolfram.com/KnapsackProblem.html

http://academicearth.org/lectures/knapsack-problem-1(MIT一個演講視頻)

好運氣,這聽起來像一個有趣的項目。

0

最後我曾在我的項目,已經完成了它

代碼:

package project; 

public class TimeTable extends Time { 
    int i; 

    String table[] = new String[24]; 
    Activity activity[]; 
    static int currentTime; 
    boolean flag = false; 

    public void setTable(Activity[] iActivity){ 
     setNontime(); 
     activity = iActivity; 
     int temp; 

     temp = clgStart- wakeTime; 
     currentTime=wakeTime; 
     System.out.println("tmep is "+temp); 
      setTimeTillCollege(temp); 

      currentTime= clgEnd; 
      temp = dinner - clgEnd; 

      System.out.println("temp is"+temp); 

      setTimeTillDinner(temp); 

      currentTime = dinner+1; 
      temp= sleepTime-dinner-1; 

      setTimeTillSleep(temp); 

     } 



    private void setTimeTillSleep(int temp) { 
     if(temp<=2){ 
      table[currentTime]= getNonAcad(); 
     } 
    } 

    private void setTimeTillDinner(int temp) { 
     if(flag){//if the academic subs are not given in daylight 
       /*   if(temp<1){ 
       table[currentTime] = "timepass"; 
      } else*/ 
       if(temp==1){ 
       table[currentTime] = getNonAcad(); 
      } else if(temp==2){ 
       table[currentTime] = getAcademic(2); 
      } else { 
       while(temp!=0){ 

       } 
      } 
     } else { 
      while(temp!=0){ 
       if(temp > 4){ 
        table[currentTime]=getAcademic(2); 
        flag=true; 
        temp-=2; 
       } else if(temp==4){ 
        table[currentTime]=getAcademic(2); 
        temp-=2; 
        table[currentTime]=getAcademic(2); 
        temp-=2; 
        flag=true; 
       } 
      } 
    } 

} 



    private void setTimeTillCollege(int temp) { 

     if(temp==1){ 
       table[currentTime] = "Revise"; 
      } else if(temp==maxSlot){ 
       table[currentTime] = getAcademic(2); 
      } else { 
       while(temp!=0){ 
        if(temp > 4){ 
         table[currentTime]=getAcademic(2); 
         flag=true; 
         temp-=2; 
        } else if(temp==4){ 
         table[currentTime]=getAcademic(2); 
         temp-=2; 
         table[currentTime]=getAcademic(2); 
         temp-=2; 
         flag=true; 
        } else if(temp<4){ 

        } else if(temp==1){ 
         getAcademic(1); 
        } 
       } 
      } 
    } 



    private String getNonAcad() { 
     for (i = 0; i < activity.length; i++) { 
      if(!activity[i].over && !activity[i].acad){ 
       activity[i].over = true; 
       currentTime+=activity[i].timeSlot; 
       return activity[i].name; 
      } 
     } 
     return null; 
    } 


    private String getAcademic(int j) { 
     for (i = 0; i < activity.length; i++) { 
      if(!activity[i].over && activity[i].credit==j){ 
       activity[i].over = true; 
       currentTime+=activity[i].timeSlot; 
       return activity[i].name; 
      } 
     } 
     return null; 
    } 

    @SuppressWarnings("unused") 
    private String getAcademic() { 
     for (i = 0; i < activity.length; i++) { 
      if(activity[i].credit==1 && activity[i].acad){ 
       activity[i].over = true; 
       currentTime+=activity[i].timeSlot; 
       return activity[i].name; 
      } 
     } 
     return null; 
    } 


    public void setNontime(){ 

     for (i = 0; i < table.length; i++) { 
      table[i]= new String(); 
     } 

     table[sleepTime]="Sleep"; 
     table[clgStart]="College"; 
     table[clgEnd]="College ends"; 
     table[dinner]= "Dinner"; 

    } 


    public void display() { 
     System.out.println("inside display method"); 
     for (i = wakeTime; i < table.length; i++) { 
       System.out.println(i+" "+table[i]); 
      } 

}} 

這是我在程序的類中的實際行動發生

活動是定義活動的名稱,時間段,信用等級的類。 時間是定義像wakeTime,sleepTime等不同時間的類。

並且在時間表類的時間表中生成

這是基於控制檯程序,我還創建其GUI應用