本文整理汇总了C++中Evaluator类的典型用法代码示例。如果您正苦于以下问题:C++ Evaluator类的具体用法?C++ Evaluator怎么用?C++ Evaluator使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Evaluator类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: theFormRange
inline bool Type_::GiveTerm(Evaluator & theEvaluator) {
if (
this->thisExpression.IsEmpty()
) {
return false;
}
Expression::FormRange<Form> theFormRange(this->thisExpression);
assert(theFormRange);
if (
theFormRange->GetOperator().IsEmpty()
) {
Operand theOperand;
{
Form::OperandRange<Operand> theOperandRange(*theFormRange);
assert(theOperandRange);
theOperand.Swap(*theOperandRange);
}
this->thisExpression.FrontPopTerm();
theEvaluator.TakeOperand(
*this,
theOperand
);
} else {
Operator theOperator;
this->thisExpression.FrontGiveTerm(theOperator);
theEvaluator.TakeOperator(
*this,
theOperator
);
}
return true;
}
示例2: ui
void ui()
{
Evaluator eval;
std::string input;
std::cout << "\ntype an expression, \"exit\" to end\n";
while (true)
{
std::cout << ">>> ";
std::getline(std::cin, input);
if (input[0] == 'e' || input[0] == 'E')
break;
try
{
std::cout << eval.eval(input) << std::endl;
}
catch (std::invalid_argument err)
{
std::cout << "Error: " << err.what() << std::endl;
}
}
}
示例3: main
int main()
{
Evaluator eval;
vector<string> expression = { "1+2*3","2+2^2*3" ,"1==2", "1+3 > 2", "(4>=4) && 0", "(1+2)*3" }; //<--expressions we wish to evaluate go here
vector<string>::iterator exprItr;
for (exprItr = expression.begin();
exprItr != expression.end();
exprItr++)
{
try
{
int result = eval.eval(*exprItr);
cout << eval.infix_expression.c_str() << " = " << result << endl << endl;
}
catch (Syntax_Error e)
{
cout << eval.infix_expression.c_str() << endl << e.what() << " " << "@ char: " << eval.position << endl << endl;
}
}
system("pause");
return 0;
}
示例4: getDelegateEvaluators
bool FieldmlSession::getDelegateEvaluators( FmlObjectHandle handle, vector<FmlObjectHandle> &stack, set<FmlObjectHandle> &delegates )
{
set<FmlObjectHandle> evaluators;
if( handle == FML_INVALID_HANDLE )
{
//Convenience so that callers don't have to check
return true;
}
if( FmlUtil::contains( stack, handle ) )
{
//Recursive dependency!
return false;
}
//TODO: Figure out why this works even though there's no popping happening.
stack.push_back( handle );
Evaluator *evaluator = Evaluator::checkedCast( this, handle );
if( evaluator != NULL )
{
if( evaluator->addDelegates( evaluators ) )
{
if( !getDelegateEvaluators( evaluators, stack, delegates ) )
{
return false;
}
}
}
return true;
}
示例5:
/*static*/ void
Thread::ThreadProc(void* pvoid)
{
// Create an evaluator
Evaluator eval;
// Run code
eval.Eval((Object*)pvoid);
}
示例6: main
int main(int argc, char** argv) {
std::string expr = "w x z - +";
Evaluator* sentence = new Evaluator(expr);
std::map<std::string, Expr*> variables = new std::map<std::string, Expr*>();
variables.put("w", new Number(5));
variables.put("x", new Number(10));
variables.put("z", new Number(32));
int result = sentence->interpret(variables);
std::cout << "Computation result: " << result << std::endl;
}
示例7: evaluate
int evaluate(T& src) {
Evaluator e;
try {
e.eval(src);
return 0;
} catch (const Error& e) {
std::cerr << DASHES << std::endl;
std::cerr << "Unhandled exception!" << std::endl << std::endl;
std::cerr << e.what() << std::endl;
std::cerr << DASHES << std::endl;
return 1;
}
}
示例8: Java_com_starlon_libscriptable_UtilsEvaluator_evaluate
JNIEXPORT jstring JNICALL Java_com_starlon_libscriptable_UtilsEvaluator_evaluate(
JNIEnv *env, jclass clazz, jobject obj, jstring str)
{
Evaluator *eval = getObjectFromCPtr<Evaluator *>( env, obj );
jboolean isCopy;
const char * _str = env->GetStringUTFChars(str, &isCopy);
std::string val = eval->Eval((std::string)_str);
env->ReleaseStringUTFChars(str, _str);
return env->NewStringUTF(val.c_str());
}
示例9: BeginSearch
int32 SearchAlgorithm::BeginSearch(int32 a_turn, uint32 a_depthRemain, Board &a_board, Evaluator &a_evaluator, uint32 &a_countNodes)
{
m_bestMoves.clear();
m_bestMoves.resize(MAX_SEARCH_DEPTH);
a_board.ClearTakenChesses();
a_evaluator.Evaluate(a_board);
m_transpositionTable->InitByBoard(a_turn, a_board);
m_currentDepth = 0;
int32 score = Search(a_turn, a_depthRemain, a_board, a_evaluator, a_countNodes);
if (!GetBestMoves().empty())
{
MovePos bestMove = *(GetBestMoves().begin());
GetTranspositionTable()->ChangeKeyByMoving(a_board.GetTypeAt(bestMove.from), bestMove.from, a_board.GetTypeAt(bestMove.to), bestMove.to);
m_boardLog.push_back(GetTranspositionTable()->GetCurrentKey());
GetTranspositionTable()->ChangeKeyByMoving(a_board.GetTypeAt(bestMove.from), bestMove.from, a_board.GetTypeAt(bestMove.to), bestMove.to);
}
++m_currentPlay;
return score;
}
示例10: center
// This method is called by the Solver object at every iteration.
bool RandomSearcher::search(const unsigned int max_dim,
const double delta, const double * poll_center,
std::vector<AugmentedPoint *> & list_of_points,
Evaluator & eval)
{
if (display_factor >= 3)
{
cout << "\nStart of random search: " << search_pts << " points, ";
cout << "delta = "<< delta << "\n-----------------------\nPoll center (";
for (unsigned int i = 0; i < max_dim - 1; i++)
cout << poll_center[i] << " ";
cout << poll_center[max_dim - 1] << ")\n";
cout << "\nCurrent best iterate: ";
eval.showIncumbent();
cout << "\n";
}
//
createArrays(max_dim, delta, poll_center);
/* This function call returns the number of points the random search will
generate. */
double nb_of_points = generateHowManyPts(max_dim);
/* This function creates the list of points that will be sent to 'Evaluator',
from the list of shuffled points. */
fillTheList(max_dim, delta, poll_center, nb_of_points, list_of_points);
// The 'complete_search' variable is returned.
return (complete_search);
}
示例11: main
int main(int argc, const char** argv) {
std::unique_ptr<Expr> c1(new Constant(1.1));
std::unique_ptr<Expr> c2(new Constant(2.2));
std::unique_ptr<Expr> p1(new BinaryPlus(*c1, *c2));
std::unique_ptr<Expr> p2(new BinaryPlus(*p1, *c2));
Stringifier s;
p2->Accept(&s);
std::cout << s.GetStringForExpr(*p2) << "\n";
Evaluator e;
p2->Accept(&e);
std::cout << e.GetValueForExpr(*p2) << "\n";
return 0;
}
示例12: get_length
Expr*
get_length(Layout_decl const* layout)
{
Evaluator eval;
Expr* e = 0;
for (Decl* d : layout->fields()) {
Type const* t1 = d->type();
// If member is constant, just add in the constant value
if (has_constant_length(t1))
e = add(e, make_int(precision(t1)));
// Otherwise, we have to form a call to the function
// that would compute this type.
else {
// FIXME: Do this right!
throw std::runtime_error("unimplemented dynamic length calc.");
e = add(e, zero());
}
}
// Compute ceil(e / 8).
Expr* b = make_int(8); // bits per byte
Expr* r = div(sub(add(e, b), one()), b);
// Try folding the result. If it works, good. If not,
// just return the previously computed expression.
//
// TODO: Maximally reduce the expression so that we only
// add the constant bits to the non-constant bits. Since
// addition is associative and commutative, we can
// partition the sequence of terms into constants and
// non-constants, and then sum the constant parts.
try {
Value v = eval.eval(r);
if (v.is_integer())
return make_int(v.get_integer());
else
throw std::runtime_error("failed to synth length");
}
catch(...) {
return r;
}
}
示例13: binary_tournament
// Compare solution with a randomly generated opponent, return whichever
// has the higher fitness
void hill_climb::binary_tournament(Random & rand, vector<bool> & solution,
float & fitness, Evaluator& evaluator) {
auto guess = rand_vector(rand, solution.size());
float guess_fitness = evaluator.evaluate(guess);
if (fitness < guess_fitness) {
solution = guess;
fitness = guess_fitness;
}
}
示例14: evaluate
bool TestDocument::evaluate(Evaluator &evaluator) {
bool rval = true;
XMLSize_t numpass = 0;
XMLSize_t numfail = 0;
std::map<char *, bool, ltcstr> test_state;
XMLCh *TEST = xercesc::XMLString::transcode("test");
XMLCh *PREREQ = xercesc::XMLString::transcode("prereq");
xercesc::DOMElement *root = doc->dom->getDocument()->getDocumentElement();
xercesc::DOMNodeList *tests = root->getElementsByTagName(TEST);
XMLSize_t numtests = tests->getLength();
std::cout << numtests << " tests found in " << doc->path << std::endl;
for (int i = 0; i < numtests; i++) {
xercesc::DOMElement *e = static_cast<xercesc::DOMElement*>(tests->item(i));
Test test(*this, e);
bool testval = true;
std::cout << "test " << (i+1) << " of " << numtests << ": " << test.id << "... ";
if (e->hasAttribute(PREREQ)) {
char *prereqs = xercesc::XMLString::transcode(e->getAttribute(PREREQ));
char *scan = prereqs;
std::stringstream prereq;
while (char c = *scan++) {
if (c == ' ' || c == ',') {
testval = __checkPrereq(test, test_state, prereq) && testval;
prereq.str("");
}
else {
prereq << c;
}
}
testval = __checkPrereq(test, test_state, prereq) && testval;
xercesc::XMLString::release(&prereqs);
}
if (testval) {
testval = evaluator.evaluate(*this, test) && testval;
testval = js_evaluator.evaluate(*this, test) && testval;
}
if (testval) {
std::cout << "[OK]";
numpass++;
}
else {
std::cout << "[FAIL] (" << test.messages.str() << ")";
numfail++;
}
std::cout << std::endl;
test_state[xercesc::XMLString::replicate(test.id)] = testval;
rval = testval && rval;
}
for (std::map<char *, bool, ltcstr>::iterator i = test_state.begin(); i != test_state.end(); i++) {
xercesc::XMLString::release((char**)&i->first);
}
xercesc::XMLString::release(&TEST);
xercesc::XMLString::release(&PREREQ);
std::cout << numpass << " of " << numtests << " tests passed, " << numfail << " failed (" << ( ((double)numpass) / ((double)numtests) * 100.0 ) << "%)" << std::endl;
return rval;
}
示例15: main
void main(){
// Construct the Context first
map<string,int> Dict;
Dict["一"] = 1;
Dict["二"] = 2;
Dict["三"] = 3;
Dict["四"] = 4;
Dict["五"] = 5;
Dict["六"] = 6;
Dict["七"] = 7;
Dict["八"] = 8;
Dict["九"] = 9;
Evaluator myEvaluator = Evaluator();
myEvaluator.Construct("五加二");
double result = myEvaluator.Interprete(Dict);
cout<<result<<endl;
while(1){
}
}