⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 stringresolution.h

📁 本遗传算法是保留大量状态种群的随机爬山搜索算法
💻 H
字号:
// StringResolution.h: interface for the CStringResolution class.
//
//////////////////////////////////////////////////////////////////////

#if !defined(AFX_STRINGRESOLUTION_H__DC52723E_F93F_4613_A5AD_F6F5BF522A54__INCLUDED_)
#define AFX_STRINGRESOLUTION_H__DC52723E_F93F_4613_A5AD_F6F5BF522A54__INCLUDED_

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
#include <stack>
using namespace std;

#define LEVELS 6
#define DERROR 0.0000001
#define BIGNUMBER 9999999.0
#define UNARY 0
#define BINARY 1

class COperator  
{
public:
	COperator();
	~COperator();
	CString m_operator;//operator name
	WORD m_level;//+,- : 0 level; *,/ :1 level; ^: 2 level; function:3 level. 
				//level add LEVELS if operator in a bracket.
	WORD m_type;//0--unary operator, 1--binary operator,...
	WORD m_startIndex;// start index which in formula
};

class COperand  
{
public:
	COperand();
	~COperand();
	BOOL operator ==(const COperand&od);//judge two operand are equal or not
	CString m_name;//digital string or variant name
	BOOL m_IsConst;//TRUE when it is digital, FALSE otherwise
	WORD m_startIndex;//start index which in formula
};

typedef stack<COperator*> OperatorStack;
typedef stack<COperand*> OperandStack;

class CStringResolution  
{
public:
	void Destroy();
	BOOL ExpressionIsError();//TRUE when expression has errors,FALSE otherwise.But when no include my.h,always FALSE.
	CString GetDigitalString(double* variantValue=0,int num=-1);//replace variant as it's value
	int GetErrorNumber();//get error number,always 0 when no include my.h
	CString GetErrorInformation();//get the error description, 
								//always "There is no error information." when no include my.h
	double computer(double variantValue[],int num);//evaluate variant(s) in m_oprandA by variantValue,then computing.
	void SetFormula(char*formula);//reset formula
	CStringResolution(char*formula=0);//constructor
	int GetVariantTableSize(){return m_oprandANum;}//get variant number
	const COperand* GetVariantTable();// get variant table
	~CStringResolution();//destructor
protected:
#ifdef _ERROR_INFO_H_
	DECLEAR_CATCH_ERROR
#endif
	int m_oprandNum;//operand number
	int m_oprandANum;//variant number
	int m_operatorNum;//operator number
	CString m_formula;//formula string
	COperator*m_operator;//pointer points to operators set
	COperand*m_oprand;//pointer points to operands set
	COperand*m_oprandA;//pointer points to variants set
	int IsFormula();//formula is availability or not.
	BOOL GetStack(OperatorStack &Op, OperandStack &Od);//get operators stack and operands stack.
	BOOL Initialize();//initialize variant member by m_formula.
	double Computer(OperatorStack &Operator, OperandStack &Oprand);//computing by stack.
	BOOL EmptyStack(OperatorStack st);//empty stack
	BOOL EmptyStack(OperandStack st);//
	BOOL GetOperandStack(OperandStack&Oprand,CString&string);//get operator stack in formula.
	BOOL GetOperatorStack(OperatorStack&Operator,CString &s);//get operand stack after GetOperandStack.
	double computing(const COperator*op,const COperand*oprand);//unary computing
	double computing(const COperator*op,const COperand*Loprand,const COperand*Roprand);//binary computing
};



#endif // !defined(AFX_STRINGRESOLUTION_H__DC52723E_F93F_4613_A5AD_F6F5BF522A54__INCLUDED_)

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -