From 3a0bac60d66789e548846b5dfe6c0a246dae057c Mon Sep 17 00:00:00 2001 From: kobayashi <3011850@gmail.com> Date: Sun, 25 Jan 2015 19:40:10 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=8C=E6=88=90RecommandPoint=E9=A1=9E?= =?UTF-8?q?=E5=88=A5(=E9=9C=80=E8=A6=81=E5=81=9A=E5=96=AE=E5=85=83?= =?UTF-8?q?=E6=B8=AC=E8=A9=A6)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- htdocs/lib/Database/DBRecommand.php | 2 +- htdocs/lib/Recommand/RecommandPoint.php | 84 +++++++++++++++++++++++-- htdocs/lib/Study/Theme.php | 13 ++++ 3 files changed, 94 insertions(+), 5 deletions(-) diff --git a/htdocs/lib/Database/DBRecommand.php b/htdocs/lib/Database/DBRecommand.php index 043a28d..f839f16 100644 --- a/htdocs/lib/Database/DBRecommand.php +++ b/htdocs/lib/Database/DBRecommand.php @@ -89,7 +89,7 @@ class DBRecommand extends Database /** * 以目前的學習點編號查詢下一個學習點的資訊 * @param string $currentPoint 目前的學習點編號 - * @return array 查詢結果 + * @return array */ public function queryEdgeByID($currentPoint) { diff --git a/htdocs/lib/Recommand/RecommandPoint.php b/htdocs/lib/Recommand/RecommandPoint.php index df903e5..e0f1f22 100644 --- a/htdocs/lib/Recommand/RecommandPoint.php +++ b/htdocs/lib/Recommand/RecommandPoint.php @@ -37,6 +37,8 @@ class RecommandPoint const ALPHA=0.5; private $recommand; + private $theme; + private $activity; public function __construct() @@ -52,11 +54,11 @@ class RecommandPoint private function computeNormalizationParameter($theme_number) { $normal = 0; //正規化之後的GAMMA值 - $EntitySum = 0; //實體學習點分別算銓重之後的值 - $VirtualSum = 0; //虛擬學習點分別算銓重之後的值 + $EntitySum = 0; //實體學習點分別算權重之後的值 + $VirtualSum = 0; //虛擬學習點分別算權重之後的值 $edge = $this->recommand->queryEdgeByID('0'); - $theme = new Study\Theme($theme_number); + $this->theme = new Study\Theme($theme_number); for($i=0;$iisTargetLearned($target_id)) return true; + else return false; + } + + /** + * 過濾非法的標的 + * + */ + private function excludeIrregularTarget($point_list,$activityObj) + { + $regularTarget = array(); + for($i=0;$iisEnableTargetId($a)ctivityObj,$nextPoint)) array_push($reregularTarget,$point_list[i]); + } + return $regularTarget; + } + /** * 推薦學習點 + * @param int $current_point 目前的標的編號 + * @param int $theme_number 主題編號 + * @param int activity_number 學習活動編號 * @return array 學習點清單 */ - public function recommand($current_point,$theme_number,$activity_number) + public function recommand($current_point,$activity_number) { + $this->activity = new Study\StudyActivity($activity_number); + $themeID = $activity->getThemeId(); + $this->theme = new Study\Theme($themeID); + $this->gamma = $this->computeNormalizationParameter($themeID); + $pointList = $this->recommand->queryEdgeByID($current_point); + $targetList = $this->excludeIrregularTarget($pointList,$this->activity); + //計算路徑的權重值 + $pathCost = 0; + $VirtualPathCost = 0; + $recommand = array(); + $isEntity = true; + for($i=0;$itheme->getWeightByNextTarget($next_point); + if($nextPoint->isFullPeople()) + { + $pastCost = 0; + $virtualCost = RecommandPoint::ALPHA * $this->gamma * ($wright/$nextPoint->getLearnTime()); + $isEntity=false; + } + else + { + if($nextPoint->isNumberOfPeopleZero()) $Rj = 0; + else $Rj = $nextPoint->getMj()/$nextPoint->getPLj(); + $pastCost = RecommandPoint::ALPHA * $this->gamma * ($weight * ($nextPoint->getS()-$Rj+1)/$moveTime + $nextPoint->getLearnTime()); + $virtualCost = RecommandPoint::ALPHA * $this->gamma * ($wright/$nextPoint->getLearnTime()); + } + array_push($recommand,array("nextPoint"=>$nextPoint, + "isEntity" => $isEntity, + "PathCost"=>$pathCost, + "VirtualCost"=>$virtualCost)); + } + + foreach($recommand as $key=>$value) + { + $tmp[$key] = $value["PathCost"]; + } + array_multisort($tmp,SORT_DESC,$recommand,SORT_DESC); + + return $recommand; } } diff --git a/htdocs/lib/Study/Theme.php b/htdocs/lib/Study/Theme.php index d255601..a03e734 100644 --- a/htdocs/lib/Study/Theme.php +++ b/htdocs/lib/Study/Theme.php @@ -6,6 +6,7 @@ namespace UElearning\Study; require_once UELEARNING_LIB_ROOT.'/Database/DBTheme.php'; +require_once UELEARNING_LIB_ROOT.'/Database/DBRecommand.php'; require_once UELEARNING_LIB_ROOT.'/Study/Exception.php'; use UElearning\Database; use UElearning\Exception; @@ -166,4 +167,16 @@ class Theme { return $this->queryResultArray['modify_time']; } + /** + * 取得下一個標的所屬主題的權重 + * @param string $next_point + * @return int weight 權重 + * @since 2.0.0 + */ + public function getWeightByNextTarget($next_point){ + $belong = new Database\DBRecommand(); + $weight = $belong->queryBelongByID($next_point,$this->id); + return $weight['weight']; + } + }