Ejemplo n.º 1
0
long expression1() {
	long result = expression2();
	while (peek() == '*' || peek() == '/' || peek() == '%')
		if (peek() == '*') {
			get();
			result *= expression2(); 	
		} else if (get() == '/')
			result /= expression2();
		else
			result %= expression2();
	return result;
}
Ejemplo n.º 2
0
int expression1(void)
{
	int sum1=0;
	for(j=0;j<=4;j++)
		sum1 += (i+j)*expression2();
	j=0;
	return sum1;
} 
Ejemplo n.º 3
0
    void TestWriteVectorOfRegexWithIndex(void)
    {
        // Marshal a vector of SCXRegexWithIndex structures
        stringstream stream;
        SCXCoreLib::Marshal msobj(stream);
        vector<SCXCoreLib::SCXRegexWithIndex> vri;

        SCXCoreLib::SCXRegexWithIndex ri1;
        std::wstring expression1(L"abc");
        ri1.index = 1;
        ri1.regex = new SCXCoreLib::SCXRegex(expression1);
        SCXCoreLib::SCXRegexWithIndex ri2;
        std::wstring expression2(L"def");
        ri2.index = 2;
        ri2.regex = new SCXCoreLib::SCXRegex(expression2);

        vri.push_back(ri1);
        vri.push_back(ri2);
        msobj.Write(vri);

        // UnMarshal and verify that it's correct
        SCXCoreLib::UnMarshal unobj(stream);

        vector<SCXCoreLib::SCXRegexWithIndex> vri2;
        unobj.Read(vri2);

        CPPUNIT_ASSERT_EQUAL(vri.size(), vri2.size());
        for(int ii = 0; ii < (int) vri.size(); ii++)
        {
            CPPUNIT_ASSERT_EQUAL(vri[ii].index, vri2[ii].index);
            CPPUNIT_ASSERT(vri[ii].regex->Get() == vri2[ii].regex->Get());
        }

        // Assure that the received regular expressions are actually correct
        CPPUNIT_ASSERT_EQUAL(std::string("abc"), SCXCoreLib::StrToUTF8(vri2[0].regex->Get()));
        CPPUNIT_ASSERT_EQUAL(std::string("def"), SCXCoreLib::StrToUTF8(vri2[1].regex->Get()));
    }
Ejemplo n.º 4
0
extern  void OptimizeFace(
	const string &OptName, 
	const vector<string> &variate, 
	const vector<double> &lower,
	const vector<double> &upper, 
	const vector<string> &target,
	const int &MaxTime,
	const int &MaxNumberIteration,
	const double &AbsoluteConvergenceCriteria,
	const double &RelativeConvergenceCriteria
)
{
	Session *theSession = Session::GetSession();
	Part *workPart(theSession->Parts()->Work());

	Optimization::OptimizationBuilder *optimizationBuilder1;
	optimizationBuilder1 = workPart->Optimization()->CreateOptimizationBuilder();

	optimizationBuilder1->SetStudyName(OptName);

	std::vector<NXString> attributenames(target.size());
	std::vector<NXObject *> attributeobjects(target.size());
	NXObject *nullNXObject(NULL);
	std::vector<Optimization::OptimizationBuilder::OptimizationAttributeType> objectivetypes(target.size());
	std::vector<double> objectivetargetvalues(target.size());
	for (int i = 0; i < target.size(); ++i)
	{
		attributenames[i] = target[i];
		attributeobjects[i] = nullNXObject;
		objectivetypes[i] = Optimization::OptimizationBuilder::OptimizationAttributeTypeKFAttribute;
		objectivetargetvalues[i] = 10;
	}
	optimizationBuilder1->SetOptimizationObjectives(attributenames, attributeobjects, objectivetypes, objectivetargetvalues);

	std::vector<NXString> attributenames2(variate.size());
	std::vector<NXObject *> attributeobjects2(variate.size());
	std::vector<Optimization::OptimizationBuilder::OptimizationAttributeType> variabletypes1(variate.size());
	for (int i = 0; i < variate.size(); ++i)
	{
		attributenames2[i] = variate[i];
		Expression *expression2(dynamic_cast<Expression *>(workPart->Expressions()->FindObject(variate[i])));
		attributeobjects2[i] = expression2;
		variabletypes1[i] = Optimization::OptimizationBuilder::OptimizationAttributeTypeExpression;
	}
	std::vector<double> variablelowerlimitvalue1 = lower;
	std::vector<double> variableupperlimitvalue1 = upper;
	optimizationBuilder1->SetOptimizationVariables(attributenames2, attributeobjects2, variabletypes1, variablelowerlimitvalue1, variableupperlimitvalue1);

	optimizationBuilder1->SetOptimizationType(Optimization::OptimizationBuilder::OptimizationTargetTypeMinimum);

	optimizationBuilder1->SetAlgorithmType(Optimization::OptimizationBuilder::OptimizationAlgorithmTypePowell);

	optimizationBuilder1->SetConvergenceSpeedType(Optimization::OptimizationBuilder::OptimizationConvergenceSpeedTypeFast);

	optimizationBuilder1->SetMaxTime(MaxTime);

	optimizationBuilder1->SetMaxNumberIteration(MaxNumberIteration);

	optimizationBuilder1->SetAbsoluteConvergenceCriteria(AbsoluteConvergenceCriteria);

	optimizationBuilder1->SetRelativeConvergenceCriteria(RelativeConvergenceCriteria);

	optimizationBuilder1->SetShowGraph(false);

	optimizationBuilder1->RunOptimization();

	optimizationBuilder1->Destroy();
}
Ejemplo n.º 5
0
int main(int argc, char ** argv) {
    if (argc < 2) {
        std::cout << "ps7a [input file]" << std::endl;
        return -1;
    }

    std::ifstream inputfile(argv[1]);  ///< Opens input file based on argv[1]
    if (!inputfile) {
        std::cout << "Could not open " << argv[1] << std::endl;
        return -1;
    }

    std::ofstream outputfile;  ///< Opens output file based on argv[1] w/ .rpt
    std::string outputfilename = argv[1];
    outputfilename += ".rpt";
    outputfile.open(outputfilename.c_str());
    if (!outputfile) {
        std::cout << "Could not open output file" << std::endl;
        return -1;
    }

    int linenum = 0;   ///< Keeps track of line number in file
    std::string temp;   ///< Stores line to use regex with
    bool test = false;   ///< To help determine if failure or not
    std::string tdatet;   ///< Stores the terminating time
    std::string datet;    ///< Stores the beginning time

    boost::regex expression(".*\\(log\\.c\\.166\\) server started");
    boost::regex expression2("[0-9]{2}:[0-6][0-9]:[0-9]{2}");
    boost::regex expression3
    (".*oejs\\.AbstractConnector:Started SelectChannelConnector");
    boost::smatch fmatch;
    boost::smatch dmatch;
    boost::smatch sumatch;


    /**
     *  This while loop gets a line from the file
     *
     *  It then increases the line count since the linenum starts at
     *  0 but the file starts at line 1
     *
     *  The loop then checks to see if we already found success denoted by test. If
     *  test is true we then check to see if we match the correct terminating command
     *  If the command matches using regex, we than extract the time and subtract it from
     *  The starting time, we set test to false, and we output all this to the file.
     *
     *  If test is true and we find another instance of the server starting, there was a failure
     *
     *  The most important part of this loop tests to see when (log.c.166) is called which
     *  is an instance of the server starting. We record the line number its on, when it starts
     *  and then we move on to our checks by setting test to true.
     *
     */
    while (std::getline(inputfile, temp)) {
        ++linenum;
        if (test) {
            if (boost::regex_search(temp, sumatch, expression3)) {
                outputfile << " success";
                tdatet = sumatch[0];
                if (boost::regex_search(tdatet, dmatch, expression2)) {
                    tdatet = dmatch[0];
                    boost::posix_time::time_duration time2
                    (boost::posix_time::duration_from_string(datet));
                    boost::posix_time::time_duration time1
                    (boost::posix_time::duration_from_string(tdatet));
                    time2 = time1 - time2;
                    std::string time = to_simple_string(time2);
                    outputfile << " " << time << std::endl;
                }
                test = false;
            } else {
                if (boost::regex_search(temp, fmatch, expression)) {
                    outputfile << " failure" << std::endl;
                    test = false;
                }
            }
        } else {
            if (boost::regex_search(temp, fmatch, expression)) {
                datet = fmatch[0];
                if (boost::regex_search(datet, dmatch, expression2)) {
                    outputfile << linenum << " " << datet;
                    datet = dmatch[0];
                    test = true;
                }
            }
        }
    }

    /**
     * 
     *  If for some reason we reach the end of the file and the server was never
     *  properly shutdown, we get a success as it will do that automatically.
     *
     */
    if (test) {
        outputfile << " success" << std::endl;
    }

    outputfile.close();
    inputfile.close();

    return 0;
}