📄 gsearch.cpp
字号:
/* Copyright (C) 2006, Mike Gashler This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. see http://www.gnu.org/copyleft/lesser.html*/#include "GSearch.h"#include <string.h>GRealVectorCritic::GRealVectorCritic(int nVectorSize){ m_nVectorSize = nVectorSize; m_dBestError = 1e100; m_pBestYet = new double[nVectorSize]; int i; for(i = 0; i < nVectorSize; i++) m_pBestYet[i] = 0;}GRealVectorCritic::~GRealVectorCritic(){ delete(m_pBestYet);}double GRealVectorCritic::Critique(double* pVector){ double dError = ComputeError(pVector); if(dError < m_dBestError) { m_dBestError = dError; memcpy(m_pBestYet, pVector, sizeof(double) * m_nVectorSize); } return dError;}// -------------------------------------------------------GRealVectorSearch::GRealVectorSearch(GRealVectorCritic* pCritic){ m_pCritic = pCritic;}/*virtual*/ GRealVectorSearch::~GRealVectorSearch(){}// -------------------------------------------------------double* GActionPath::AddAction(double dError, int nAction, double* pNewState){ GAction* pPrevAction = m_pLastAction; m_pLastAction = new GAction(nAction, pPrevAction); m_pLastAction->AddRef(); // referenced by m_pLastAction pPrevAction->Release(); // no longer referenced by m_pLastAction m_nPathLen++; m_dError = dError; double* pOldState = m_pState; m_pState = pNewState; return pOldState;}// -------------------------------------------------------GActionPathCritic::GActionPathCritic(double* pStartState, int nVectorSize, int nActionCount) : m_paths(16), m_nActionCount(nActionCount), m_nVectorSize(nVectorSize){ m_paths.AddPointer(new GActionPath(pStartState, nVectorSize)); m_dBestError = 1e100;}// virtualGActionPathCritic::~GActionPathCritic(){ int nCount = m_paths.GetSize(); int i; for(i = 0; i < nCount; i++) delete((GActionPath*)m_paths.GetPointer(i));}double GActionPathCritic::CritiqueAction(GActionPath* pPath, int nAction, double* pNewState){ double dError = ComputeError(pPath, nAction, pNewState); if(dError < m_dBestError) { m_pBestPath = pPath; m_dBestError = dError; } return dError;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -