Fix 導引演算法

This commit is contained in:
Yuan Chiu 2015-03-16 16:20:42 +08:00
parent 61642d9846
commit 85095457cc
2 changed files with 32 additions and 17 deletions

View File

@ -1353,6 +1353,16 @@ $app->group('/tokens', 'APIrequest', function () use ($app, $app_template) {
// 取得本次採用的教材風格 // 取得本次採用的教材風格
$materialMode = $sact->getMaterialStyle(); $materialMode = $sact->getMaterialStyle();
// 是否已經學完了
if($sact->getRemainingPointTotal() <= 0) {
$isEnd = true;
$recommandResult = array();
$recommandTotal = 0;
}
else {
$isEnd = false;
// 取得推薦的學習點 // 取得推薦的學習點
$recommand = new Recommand\RecommandPoint(); $recommand = new Recommand\RecommandPoint();
$recommandResult = $recommand->recommand($currentTId, $saId); $recommandResult = $recommand->recommand($currentTId, $saId);
@ -1363,12 +1373,6 @@ $app->group('/tokens', 'APIrequest', function () use ($app, $app_template) {
else { else {
$result_recommand_total = $recommandTotal; $result_recommand_total = $recommandTotal;
} }
// 是否已經學完了
if($sact->getRemainingPointTotal() <= 0) {
$isEnd = true;
}
else {
$isEnd = false;
} }
// 製作 // 製作

View File

@ -128,6 +128,7 @@ class RecommandPoint
{ {
$this->activity = new Study\StudyActivity($activity_number); $this->activity = new Study\StudyActivity($activity_number);
$themeID = $this->activity->getThemeId(); $themeID = $this->activity->getThemeId();
$enableVirtual = $this->activity->isEnableVirtual();
$this->theme = new Study\Theme($themeID); $this->theme = new Study\Theme($themeID);
$this->gamma = $this->computeNormalizationParameter($themeID); $this->gamma = $this->computeNormalizationParameter($themeID);
$pointList = $this->recommand->queryEdgeByID($current_point); $pointList = $this->recommand->queryEdgeByID($current_point);
@ -137,31 +138,41 @@ class RecommandPoint
$pathCost = 0; $pathCost = 0;
$VirtualPathCost = 0; $VirtualPathCost = 0;
$recommand = array(); $recommand = array();
$isEntity = true;
for($i=0;$i<count($targetList);$i++) for($i=0;$i<count($targetList);$i++)
{ {
$next_point = $targetList[$i]["next_point"]; $next_point = $targetList[$i]["next_point"];
$moveTime = $targetList[$i]["move_time"]; $moveTime = $targetList[$i]["move_time"];
$nextPoint = new Target\Target($next_point); $nextPoint = new Target\Target($next_point);
$weight = $this->theme->getWeightByNextTarget($next_point); $weight = $this->theme->getWeightByNextTarget($next_point);
if($nextPoint->isFullPeople()) if($nextPoint->isFullPeople())
{ {
$pastCost = 0; $pathCost = 0;
$virtualCost = RecommandPoint::ALPHA * $this->gamma * ($weight/$nextPoint->getLearnTime()); $virtualCost = RecommandPoint::ALPHA * $this->gamma * ($weight/$nextPoint->getLearnTime());
$isEntity=false; $isEntity=false;
}
else if($enableVirtual) {
{
if($nextPoint->isNumberOfPeopleZero()) $Rj = 0;
else $Rj = $nextPoint->getMj()/$nextPoint->getPLj();
$pathCost = RecommandPoint::ALPHA * $this->gamma * ($weight * ($nextPoint->getS()-$Rj+1)/($moveTime + $nextPoint->getLearnTime()));
$virtualCost = RecommandPoint::ALPHA * $this->gamma * ($weight/$nextPoint->getLearnTime());
}
array_push($recommand,array("nextPoint" => $next_point, array_push($recommand,array("nextPoint" => $next_point,
"isEntity" => $isEntity, "isEntity" => $isEntity,
"PathCost" => $pathCost, "PathCost" => $pathCost,
"VirtualCost" => $virtualCost)); "VirtualCost" => $virtualCost));
} }
}
else
{
$isEntity=true;
if($nextPoint->isNumberOfPeopleZero()) $Rj = 0;
else $Rj = $nextPoint->getMj()/$nextPoint->getPLj();
$pathCost = RecommandPoint::ALPHA * $this->gamma * ($weight * ($nextPoint->getS()-$Rj+1)/($moveTime + $nextPoint->getLearnTime()));
$virtualCost = RecommandPoint::ALPHA * $this->gamma * ($weight/$nextPoint->getLearnTime());
array_push($recommand,array("nextPoint" => $next_point,
"isEntity" => $isEntity,
"PathCost" => $pathCost,
"VirtualCost" => $virtualCost));
}
}
if(count($recommand) >= 1) { if(count($recommand) >= 1) {