当前位置: 首页>>代码示例>>C++>>正文


C++ StateSet::size方法代码示例

本文整理汇总了C++中StateSet::size方法的典型用法代码示例。如果您正苦于以下问题:C++ StateSet::size方法的具体用法?C++ StateSet::size怎么用?C++ StateSet::size使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在StateSet的用法示例。


在下文中一共展示了StateSet::size方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: UCS

/**
 * Uniform Cost Search
 */
void UCS(const vector<string> &ground)
{
	int time1 = clock();
	Statistics stat;
	priority_queue<UCSState>q;
	StateSet rec;
	UCSState init(0);
	initState(ground, init.state);
	vector<State>stateVector;
	q.push(init);
	stateVector.push_back(init.state);
	rec.insert(init.state);
	UCSState result;
	while (!q.empty()) {
		UCSState tmp = q.top();
		q.pop();
		for (int i = 0; i < 4; ++i) {
			UCSState now = tmp;
			now.state.person.x += direction[i][0];
			now.state.person.y += direction[i][1];
			int s = validState(direction[i][0], direction[i][1], now.state, ground);
			now.state.move = step[i];
			now.state.previousStateNum = now.state.currentStateNum;
			stat.anodes++;
			if (s == -1) {
				result = now;
				goto end;
			} else if (s && !rec.count(now.state)) {
				now.cost += s;
				now.state.currentStateNum = stateVector.size();
				stateVector.push_back(now.state);
				rec.insert(now.state);
				q.push(now);
			} else if (s) {
				stat.bnodes++;
			}
		}
	}
end:
	stat.cnodes = q.size();
	stat.dnodes = rec.size() + 1;
	stat.runtime = (clock() - time1) * 1.0 / CLOCKS_PER_SEC;
	outputStat(stat);
	outputSolution(stateVector, result.state);
}
开发者ID:ChongZhang1989,项目名称:SokobanSolver,代码行数:48,代码来源:ucs.cpp

示例2: DFS

/**
 * dfs to the solution
 */
void DFS(const vector<string> &ground)
{
	int time1 = clock();
	Statistics stat;
	State init;
	initState(ground, init);
	StateSet rec;
	vector<State>stateVector;
	stateVector.push_back(init);
	int flg = 0;
	State result;
	stack<State>st;
	st.push(init);
	while (!st.empty()) {
		State tmp = st.top();
		st.pop();
		for (int i = 0; i < 4; ++i) {
			State now = tmp;
			now.person.x += direction[i][0];
			now.person.y += direction[i][1];
			int s = validState(direction[i][0], direction[i][1], now, ground);
			now.move = step[i];
			now.previousStateNum = now.currentStateNum;
			stat.anodes++;
			if (s == -1) {
				result = now;
				goto end;
			} else if (s && !rec.count(now)) {
				now.currentStateNum = stateVector.size();
				st.push(now);
				stateVector.push_back(now);
				rec.insert(now);
			} else if (s) {
				stat.bnodes++;
			}
		}
	}
end:
	stat.cnodes = st.size();
	stat.dnodes = rec.size() + 1;
	stat.runtime = (clock() - time1) * 1.0 / CLOCKS_PER_SEC;
	outputStat(stat);
	outputSolution(stateVector, result);
}
开发者ID:ChongZhang1989,项目名称:SokobanSolver,代码行数:47,代码来源:dfs.cpp

示例3: simulate


//.........这里部分代码省略.........
                                / CLOCKS_PER_SEC));
                if (maxTime > -1) {
                    int planningTime = perReplan ?
                        maxTime : std::max(0, maxTime - simulationsElapsedTime);
                    solver->maxPlanningTime(planningTime);
                }
                if (algorithm != "greedy")
                    a = solver->solve(tmp);
                                                                                dprint("found action" , (void *) a);
                endTime = clock();
                double planTime =
                    (double(endTime - startTime) / CLOCKS_PER_SEC);
                totalTime += planTime;
                simulationPlanTime += planTime;
                longestTime = std::max(longestTime, planTime);
                numDecisions++;
                if (algorithm != "hop")
                    a = greedyAction(problem, tmp);
            } else {
                if (useUpperBound) {
                    // The algorithms that use upper bounds store the
                    // greedy action with respect to the upper bound
                    // in State::bestAction_
                    a = tmp->bestAction();
                }
                else {
                    a = greedyAction(problem, tmp);
                }
            }

            if (verbosity >= 1000) {
                cout << "State/Action: " << tmp << " " << a << " " << endl;
            }

            costTrial += problem->cost(tmp, a);
            costTrial = std::min(costTrial, mdplib::dead_end_cost);
            if (costTrial >= mdplib::dead_end_cost) {
                break;
            }
            double prob = 0.0;
            State* aux = randomSuccessor(problem, tmp, a, &prob);
            if (algorithm == "hdp") {
                double maxProb = 0.0;
                for (auto const & sccr : problem->transition(tmp, a))
                    maxProb = std::max(maxProb, sccr.su_prob);
                plausTrial +=
                    static_cast<HDPSolver*>(solver)->kappa(prob, maxProb);
            }
            tmp = aux;
        }
        if (verbosity >= 10)
            cout << costTrial << endl;
        if (flag_is_registered("ctp")) {
            CTPState* ctps = static_cast<CTPState*>(tmp);
            if (!ctps->badWeather()) {
                cnt++;
                updateStatistics(costTrial, cnt, expectedCost, variance);
                updateStatistics(
                    simulationPlanTime, cnt, expectedTime, varianceTime);
            }
        } else {
            cnt++;
            updateStatistics(costTrial, cnt, expectedCost, variance);
            updateStatistics(
                simulationPlanTime, cnt, expectedTime, varianceTime);
        }
        if (verbosity >=0) {
            if (cnt % 500 == 0 || i == numSims - 1) {
                double reportedTime = perReplan ?
                    totalTime / numDecisions : totalTime;
                cout << "sim " << cnt << " exp.cost " << expectedCost
                     << " var " << variance / (cnt - 1)
                     << " time " << reportedTime
                     << " longestTime  " << longestTime << " "
                     << " Exp[total time] " << expectedTime
                     << " Var[total time] " << varianceTime / (cnt - 1) << endl;
            }
        }
    }

    double reportedTime = perReplan ? totalTime / numDecisions : totalTime;

    if (verbosity >= 10) {
        cout << "Estimated cost " << problem->initialState()->cost() << " ";
        cout << "Avg. Exec cost " << expectedCost << " ";
        cout << "Std. Dev. " << sqrt(variance / (cnt - 1)) << " ";
        cout << "Total time " << totalTime / cnt << " " << endl;
        cout << "States seen " << statesSeen.size() << endl;
        cout << "Avg. time per decision "
             << totalTime / numDecisions << endl
             << "Longest planning time " << longestTime << endl;
        cout << "Num. decisions " << numDecisions << endl;
    }

    double results[] = {expectedCost,
                        variance / (cnt - 1),
                        reportedTime,
                        longestTime};
    return vector<double>(results, results + sizeof(results) / sizeof(double));
}
开发者ID:luisenp,项目名称:mdp-lib,代码行数:101,代码来源:testSolver.cpp


注:本文中的StateSet::size方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。