Ejemplo n.º 1
0
void main()
{clrscr();
Add A;
A.enter();
A.show();
getch();
}
Ejemplo n.º 2
0
Word Solver :: find_best_M (std::string operation_name, int M_index) {
    Operation * operation;
    Add * adder;
    Word result;
    
    operation = get_operation(operation_name);
    adder = dynamic_cast<Add *>(operation);
    
    result = adder->best_adder(M[M_index]->g_name());

    return result;
}
Ejemplo n.º 3
0
int 
main(
    int argc,
    char *argv[]) 
{
	Environment::initialize("calculator.log", AXIS2_LOG_LEVEL_TRACE);
	string endpointUri = "http://localhost:9090/axis2/services/Calculator";
	string clientHome = AXIS2_GETENV("WSFCPP_HOME");
	if(clientHome.empty())
	{
		cout<<"Please set the WSFCPP_HOME environment variable"<<endl;
	}
	CalculatorStub *stub = new CalculatorStub(clientHome, endpointUri);
	Add *addIn = new Add();
	addIn->setA(10);
	addIn->setB(10);
	AddResponse *addResponse  = stub->add(addIn);
	if(addResponse)
	{
		cout<<"Calculation, 10 + 10 result is "<<addResponse->getAddReturn()<<endl;
	}

	Sub *subIn = new Sub();
	subIn->setA(20);
	subIn->setB(10);
	SubResponse *subResponse = stub->sub(subIn);
	if(subResponse)
	{
		cout<<"Calculation, 20 - 10 result is "<<subResponse->getSubReturn()<<endl;
	}

	Mul *mulIn =  new Mul();
	mulIn->setA(15);
	mulIn->setB(15);
	MulResponse *mulResponse = stub->mul(mulIn);
	if(mulResponse)
	{
		cout<<"Calculation, 15 * 15 result is "<<mulResponse->getMulReturn() <<endl;
	}

	Div *divIn = new Div();
	divIn->setA(100);
	divIn->setB(10);
	DivResponse *divResponse = stub->div(divIn);
	if(divResponse)
	{
		cout<<"Calculation, 100/10 result is "<<divResponse->getDivReturn()<<endl;
	}
	delete stub;
}
Ejemplo n.º 4
0
    void bvisit(const Add &x)
    {

        RCP<const Basic> curr_num = zero;
        RCP<const Basic> curr_den = one;
        RCP<const Basic> arg_num, arg_den, den_mul, divx;
        RCP<const Basic> divx_num, divx_den;

        for (const auto &arg : x.get_args()) {
            // TODO: This is naive and slow. Fix it
            as_numer_denom(arg, outArg(arg_num), outArg(arg_den));

            divx = div(arg_den, curr_den);
            as_numer_denom(divx, outArg(divx_num), outArg(divx_den));
            if (eq(*divx_den, *one)) {
                // the curr_den completely divides the arg_den
                curr_den = arg_den;
                curr_num = add(mul(curr_num, divx), arg_num);
                continue;
            }

            divx = div(curr_den, arg_den);
            as_numer_denom(divx, outArg(divx_num), outArg(divx_den));
            // the below two lines, cover the general case, as well as the case
            // where arg_den completely divides curr_den
            curr_den = mul(curr_den, divx_den);
            curr_num = add(mul(curr_num, divx_den), mul(arg_num, divx_num));
        }

        *numer_ = curr_num;
        *denom_ = curr_den;
    }
Ejemplo n.º 5
0
 void bvisit(const Add &x) {
     mpfr_class t(mpfr_get_prec(result_));
     auto d = x.get_args();
     auto p = d.begin();
     apply(result_, *(*p));
     p++;
     for (; p != d.end();  p++) {
         apply(t.get_mpfr_t(), *(*p));
         mpfr_add(result_, result_, t.get_mpfr_t(), rnd_);
     }
 }
Ejemplo n.º 6
0
void NatE::simplify(){
	this->exponent->simplify();
	this->coefficient->simplify();
	if (this->coefficient->getType() == "Rational"){
		Rational* newCo = dynamic_cast<Rational*>(this->coefficient);
		if (newCo->getNumerator()->getType() == "NatE"){
			NatE* newPi = dynamic_cast<NatE*>(newCo->getNumerator());
			Add* add = new Add();
			this->exponent = add->evaluate(this->exponent, newPi->getExponent());
			newCo->setNumerator(newPi->getCoefficient());
			newCo->simplify();
			this->coefficient = newCo;
		}
		else if (newCo->getDenominator()->getType() == "NatE"){
			NatE* newPi = dynamic_cast<NatE*>(newCo->getDenominator());
			Subtract* sub = new Subtract();
			this->exponent = sub->evaluate(this->exponent, newPi->getExponent());
			newCo->setDenominator(newPi->getCoefficient());
			newCo->simplify();
			this->coefficient = newCo;
		}

	}
}
Ejemplo n.º 7
0
int main(){
   Op two(2.0);
   Base* n2 = &two;
   Op one1(1.0);
   Base* n11 = &one1;
   Op fourteen(14.0);
   Base* n14 = &fourteen;
   Op three(3.0);
   Op seven(7.0);
   Base* n7 = &seven;
   Op four(4.0);
   Op six(6.0);
   Base* n6 = &six;
   Base* n4 = &four;
   Sqr Root;
   Div divide;
   Base* di = &divide;
   Add addition;
   Base* ad = &addition;
   Mult multi;
   Base* mu = &multi;
   Sub subtr;
   Base* su = &subtr;
  // Root.addright(n2);

   Root.addleft(mu);
   addition.addleft(n11);
   addition.addright(n14);
   divide.addleft(n6);
   divide.addright(su);
   subtr.addleft(n4);
   subtr.addright(n2);
   multi.addleft(ad);
   multi.addright(di);
   cout << Root.evaluate() << endl;

cout << "Vector test with selection sort: " << endl;
Vector_C vcontainer;
Ssort selectionS;
vcontainer.add_element(n6);
vcontainer.add_element(di);
vcontainer.add_element(mu);
vcontainer.add_element(n11);
vcontainer.add_element(n7);
vcontainer.add_element(ad);
vcontainer.set_sort_function(&selectionS);
vcontainer.sort();
vcontainer.print();

cout << "Vector test with bubble sort: " << endl;
Vector_C vcontainer2;
Bsort BubbleS;
vcontainer2.add_element(n6);
vcontainer2.add_element(di);
vcontainer2.add_element(mu);
vcontainer2.add_element(n11);
vcontainer2.add_element(n7);
vcontainer2.add_element(ad);
vcontainer2.set_sort_function(&BubbleS);
vcontainer2.sort();
vcontainer2.print();

cout << "List test with selection sort: " << endl;
List_C lcontainer;

lcontainer.add_element(n6);
lcontainer.add_element(di);
lcontainer.add_element(n14);
lcontainer.add_element(n11);
lcontainer.add_element(n7);
lcontainer.add_element(ad);
lcontainer.add_element(mu);
lcontainer.set_sort_function(&selectionS);
lcontainer.sort();
lcontainer.print();

cout << "List test with bubble sort: " << endl;
List_C lcontainer2;

lcontainer2.add_element(n6);
lcontainer2.add_element(di);
lcontainer2.add_element(mu);
lcontainer2.add_element(n14);
lcontainer2.add_element(n11);
lcontainer2.add_element(n7);
lcontainer2.add_element(ad);
lcontainer2.set_sort_function(&BubbleS);
lcontainer2.sort();
lcontainer2.print();


return 0;
}
Ejemplo n.º 8
0
  void defaultGraph() 
  {
    Node* node;
    
    // create a bunch of nodes but don't connect them, user will do that
    //node = getNode<ScreenCap>(name, loc);
    //node->update();
    
    cv::Point2f loc = cv::Point2f(400,400);
    
    ImageDir* im_dir = getNode<ImageDir>("image_dir", loc);
    im_dir->dir = "../data/";
    im_dir->loadImages();

    node = getNode<Sobel>("sobel", loc);
    node = getNode<Add>("add0", loc);
    node = getNode<Add>("add1", loc);
    //node = getNode<Fir>("fir", loc);
    node = getNode<Resize>("resize", loc);
    node = getNode<Rot2D>("rot2d", loc);
    node = getNode<Signal>("signal0", loc);
    node = getNode<Signal>("signal1", loc);
    node = getNode<Saw>("saw0", loc);
    node = getNode<Saw>("saw1", loc);
    node = getNode<Saw>("saw2", loc);
    node = getNode<Tap>("tap0", loc);
    node = getNode<Tap>("tap1", loc);
    node = getNode<Tap>("tap2", loc);
    node = getNode<TapInd>("tapind0", loc);
    node = getNode<TapInd>("tapind1", loc);
    node = getNode<TapInd>("tapind2", loc);
    node = getNode<Buffer>("buffer0", loc);
    node = getNode<Buffer>("buffer1", loc);
    node = getNode<Buffer>("buffer2", loc);

    node = getNode<ImageNode>("output", loc);
    cv::Mat tmp;
    node->setImage("in", tmp); 

    //node = getNode<Output>("out", loc);

    gridGraph(); 

  #if MAKE_FIR
    {
      FilterFIR* fir = getNode<FilterFIR>("fir_filter", cv::Point2(500,150));

      // http://www-users.cs.york.ac.uk/~fisher/cgi-bin/mkfscript
      static float arr[] =  { -1.0, 3.0, -3.0, 1.0, }; //{ 0.85, -0.35, 0.55, -0.05, };
       /* {
          0.2, -0.1,
          0.2, -0.1,
          0.2, -0.1,
          0.2, -0.1,
          0.2, -0.1,
          0.2, -0.1,
          0.2, -0.1,
          0.2, -0.1,
          0.2, -0.1,
          0.2, -0.1,
          0.2, -0.1,
          0.2, -0.1,
          };*/
      /*  { +0.0000000000, -0.0025983155, +0.0000000000, +0.0057162941,
          +0.0000000000, +0.0171488822, +0.0000000000, -0.1200421755,
          -0.0000000000, +0.6002108774, +1.0000000000, +0.6002108774,
          -0.0000000000, -0.1200421755, +0.0000000000, +0.0171488822,
          +0.0000000000, +0.0057162941, +0.0000000000, -0.0025983155,
          +0.0000000000,
        };*/

      vector<float> vec (arr, arr + sizeof(arr) / sizeof(arr[0]) );

      fir->setup(vec);
      fir->setInputPort(IMAGE,"in", passthrough, "out");

      // IIR denominator
      FilterFIR* denom = getNode<FilterFIR>("iir_denom", cv::Point2f(500,350));
      static float arr2[] =  { 
                 1.7600418803, // y[n-1]
                -1.1828932620, // * y[n- 2])
                0.2780599176, // * y[n- 3])
                }; 

      vector<float> vec2 (arr2, arr2 + sizeof(arr2) / sizeof(arr2[0]) );
      denom->setup(vec2);
      denom->setInputPort(IMAGE,"in",fir, "out");
       
      Add* add_iir = getNode<Add>("add_iir", cv::Point2f(400,100) );
      add_iir->out = test_im;
      vector<ImageNode*> add_in;
      add_in.push_back(fir);
      add_in.push_back(denom);
      vector<float> nf;
      nf.push_back(1.0);
      nf.push_back(1.0);
      add_iir->setup(add_in, nf);
      
      //output = add_iir;
    }
    #endif

    #if 0
    // make a chain, sort of a filter
    bool toggle = false;
    for (float ifr = advance; ifr <= 1.0; ifr += advance ) {

      Signal* s2 = getNode<Saw>("sawl", cv::Point2f(400.0 + ifr*400.0, 200.0 + ifr*40.0) );
      s2->setup(advance, ifr);

      Tap* p2 = getNode<Tap>("tapl", cv::Point2f(400.0 + ifr*410.0, 300.0 + ifr*30.0) );
      p2->setup(s2, cam_buf);
      p2->out = test_im;

      Add* add = getNode<Add>("addl", cv::Point2f(400.0 + ifr*430.0, 400.0 + ifr*10.0) );
      add->out = test_im;
      add->setup(nd, p2, toggle ? 1.5 : 0.5, toggle? -0.5 :0.5);
      toggle = !toggle;
      /*
         Signal* s3 = new Saw(advance, ifr -advance*2.5);
         Tap* p3 = new Tap(s2, cam_buf);

         add = new Add(add, p3, 2.0, -1.0);
         */
      nd = add;
    }
  #endif

    //output = nd;
    //output = p1;
/*
    cv::namedWindow("cam", CV_GUI_NORMAL);
    cv::moveWindow("cam", 0, 0);
*/
    output_node = (Output*)node;
    saveGraph("default_graph.yml");
  }