예제 #1
0
파일: random_e2.hpp 프로젝트: ghali/DelCapo
void
set_to_random( Vector_E2<NT>& V )
{
    NT x = NT(rand()/(RAND_MAX+1.0));
    NT y = NT(rand()/(RAND_MAX+1.0));
    V = Vector_E2<NT>(x,y);
}
예제 #2
0
파일: xer.c 프로젝트: poppe34/GRIP_STACK
flag Xer_DecodeComplexElementEnd(ByteStream* pByteStrm, const char* elementTag, int *pErrCode) 
{
	Token t;
	if (NT(pByteStrm).TokenID!='<') {
		*pErrCode = ERR_INVALID_XML_FILE; /* +++ */
		return FALSE;
	}

	if (NT(pByteStrm).TokenID!='/') {
		*pErrCode = ERR_INVALID_XML_FILE; /* +++ */
		return FALSE;
	}

	t = NT(pByteStrm);
	if ((t.TokenID != WORD_ID) || (strcmp(t.Value ,elementTag)!=0)) {
		*pErrCode = ERR_INVALID_XML_FILE; /* +++ */
		return FALSE;
	}

	if (NT(pByteStrm).TokenID!='>') {
		*pErrCode = ERR_INVALID_XML_FILE; /* +++ */
		return FALSE;
	}
	
	return TRUE;
}
  Miniball<CoordAccessor>::Miniball (int d_, Pit begin, Pit end, 
				     CoordAccessor ca) 
    : d (d_), 
      points_begin (begin), 
      points_end (end), 
      coord_accessor (ca), 
      time (clock()), 
      nt0 (NT(0)), 
      L(), 
      support_end (L.begin()), 
      fsize(0), 
      ssize(0), 
      current_c (NULL), 
      current_sqr_r (NT(-1)),
      c (NULL),
      sqr_r (NULL),
      q0 (NULL),
      z (NULL),
      f (NULL),
      v (NULL),
      a (NULL)
  {	
    assert (points_begin != points_end);
    create_arrays();

    // set initial center
    for (int j=0; j<d; ++j) c[0][j] = nt0;
    current_c = c[0];

    // compute miniball
    pivot_mb (points_end);

    // update time
    time = (clock() - time) / CLOCKS_PER_SEC;
  }
예제 #4
0
파일: xer.c 프로젝트: poppe34/GRIP_STACK
flag Xer_NextStartElementIs(ByteStream* pByteStrm, const char* elementTag)
{
	Token t;
	int save = pByteStrm->currentByte;

	if (NT(pByteStrm).TokenID!='<') {
		pByteStrm->currentByte = save;
		return FALSE;
	}

	t = NT(pByteStrm);
	if ((t.TokenID != WORD_ID) || (strcmp(t.Value ,elementTag)!=0)) {
		pByteStrm->currentByte = save;
		return FALSE;
	}

	if (NT(pByteStrm).TokenID!='>') {
		pByteStrm->currentByte = save;
		return FALSE;
	}


	pByteStrm->currentByte = save;
	return TRUE;
}
예제 #5
0
파일: random_e2.hpp 프로젝트: ghali/DelCapo
void
set_to_random( Point_E2<NT>& P )
{
    NT x = NT(rand()/(RAND_MAX+1.0));
    NT y = NT(rand()/(RAND_MAX+1.0));
    P = Point_E2<NT>(x,y);
}
예제 #6
0
NT unit_part(const NT& x){
    // the unit part of 0 is defined as 1. 
    if (x == 0 ) return NT(1);

    typedef CGAL::Algebraic_structure_traits<NT> AST;
    typedef typename AST::Algebraic_category Algebraic_category; 
    return unit_part_(x,Algebraic_category());
}
예제 #7
0
파일: xer.c 프로젝트: poppe34/GRIP_STACK
Token LA(ByteStream* pByteStrm) {
	int tmp;
	Token ret;
	tmp = pByteStrm->currentByte;

	ret = NT(pByteStrm);

	pByteStrm->currentByte = tmp;

	return ret;
}
void test_zono_volume(int n, int m, NT tolerance = 0.15)
{
    typedef Cartesian<NT>    Kernel;
    typedef typename Kernel::Point    Point;
    typedef boost::mt19937    RNGType;
    typedef Zonotope<Point> Zonotope;
    Zonotope ZP = gen_zonotope<Zonotope, RNGType>(n, m);

    // Setup the parameters
    int walk_len=1;
    int nexp=1, n_threads=1;
    NT e=0.1, err=0.0000000001;
    NT C=2.0,ratio,frac=0.1,delta=-1.0, round_value = 1.0;
    int rnum = std::pow(e,-2) * 400 * n * std::log(n);
    int N = 500 * ((int) C) + ((int) (n * n / 2));
    int W = 4*n*n+500;
    ratio = 1.0-1.0/(NT(n));
    unsigned seed = std::chrono::system_clock::now().time_since_epoch().count();
    RNGType rng(seed);
    boost::normal_distribution<> rdist(0,1);
    boost::random::uniform_real_distribution<>(urdist);
    boost::random::uniform_real_distribution<> urdist1(-1,1);
    std::pair<NT,NT> res_round;

    vars<NT, RNGType> var(rnum,n,walk_len,n_threads,err,e,0,0,0,0,rng,
                          urdist,urdist1,-1.0,false,false,false,false,false,false,true,false);

    //Compute chebychev ball//
    std::pair<Point,NT> CheBall;
    CheBall = ZP.ComputeInnerBall();

    // Estimate the volume
    std::cout << "--- Testing volume of Zonotope in dimension: " << n <<" and number of generators: "<< m << std::endl;
    std::cout << "Number type: " << typeid(NT).name() << std::endl;
    NT vol_exact = exact_zonotope_vol<NT>(ZP);
    res_round = rounding_min_ellipsoid(ZP, CheBall, var);
    round_value = round_value * res_round.first;
    NT vol = 0;
    unsigned int const num_of_exp = 10;
    for (unsigned int i=0; i<num_of_exp; i++)
    {
        CheBall = ZP.ComputeInnerBall();
        vars<NT, RNGType> var2(rnum,n,10 + n/10,n_threads,err,e,0,0,0,0,rng,
                               urdist,urdist1,-1.0,false,false,false,false,false,false,true,false);
        vars_g<NT, RNGType> var1(n,walk_len,N,W,1,e,CheBall.second,rng,C,frac,ratio,delta,false,
                                 false,false,false,false,false,false,true,false);
        vol += round_value * volume_gaussian_annealing(ZP, var1, var2, CheBall);
    }
    NT error = std::abs(((vol/num_of_exp)-vol_exact))/vol_exact;
    std::cout << "Computed volume (average) = " << vol/num_of_exp << std::endl;
    std::cout << "Expected volume = " << vol_exact << std::endl;
            CHECK(error < tolerance);
}
예제 #9
0
파일: xer.c 프로젝트: poppe34/GRIP_STACK
flag Xer_LA_NextElementTag(ByteStream* pByteStrm, char* elementTag)
{
	Token t;
	int save = pByteStrm->currentByte;

	if (NT(pByteStrm).TokenID!='<') {
		pByteStrm->currentByte = save;
		return FALSE;
	}

	t = NT(pByteStrm);
	strcpy(elementTag, t.Value);
	if ((t.TokenID != WORD_ID) || (strcmp(t.Value ,elementTag)!=0)) {
		pByteStrm->currentByte = save;
		return FALSE;
	}

	t = NT(pByteStrm);
	if (t.TokenID =='/') {
		if (NT(pByteStrm).TokenID == '>') {
			pByteStrm->currentByte = save;
			return TRUE;
		} else {
			pByteStrm->currentByte = save;
			return FALSE;
		}
	} else {
		if (t.TokenID != '>') {
			pByteStrm->currentByte = save;
			return FALSE;
		}
	}



	pByteStrm->currentByte = save;
	return TRUE;
}
예제 #10
0
파일: xer.c 프로젝트: poppe34/GRIP_STACK
flag Xer_DecodeComplexElementStart(ByteStream* pByteStrm, const char* elementTag, XmlAttributeArray* pAttrs, int *pErrCode) 
{
	Token t;

	if (NT(pByteStrm).TokenID != '<') {
		*pErrCode = ERR_INVALID_XML_FILE; /* +++ */
		return FALSE;
	}
	
	t = NT(pByteStrm);
	if ( (t.TokenID != WORD_ID) || (strcmp(t.Value ,elementTag)!=0)) {
		*pErrCode = ERR_INVALID_XML_FILE; /* +++ */
		return FALSE;
	}

	if (!Xer_DecodeAttributes(pByteStrm, pAttrs, pErrCode))
		return FALSE;


	t = NT(pByteStrm);
	if (t.TokenID =='/') {
		if (NT(pByteStrm).TokenID == '>') {
			return TRUE;
		}
		else {
			*pErrCode = ERR_INVALID_XML_FILE; /* +++ */
			return FALSE;
		}
	} else {
		if (t.TokenID != '>') {
			*pErrCode = ERR_INVALID_XML_FILE; /* +++ */
			return FALSE;
		}
	}

	return TRUE;
}
예제 #11
0
파일: xer.c 프로젝트: poppe34/GRIP_STACK
flag Xer_DecodeAttributes(ByteStream* pByteStrm, XmlAttributeArray* pAttrs, int *pErrCode) 
{
	Token t1;
	Token t2;

	while(LA(pByteStrm).TokenID != '>') {
		t1 = NT(pByteStrm);
		if (t1.TokenID != WORD_ID) {
			*pErrCode = ERR_INVALID_XML_FILE; /* +++ */
			return FALSE;
		}

		if (NT(pByteStrm).TokenID!='=') {
			*pErrCode = ERR_INVALID_XML_FILE; /* +++ */
			return FALSE;
		}

		if (NT(pByteStrm).TokenID!='"') {
			*pErrCode = ERR_INVALID_XML_FILE; /* +++ */
			return FALSE;
		}

		t2 = NT(pByteStrm);
		if (t2.TokenID != WORD_ID) {
			*pErrCode = ERR_INVALID_XML_FILE; /* +++ */
			return FALSE;
		}

		if (NT(pByteStrm).TokenID!='"') {
			*pErrCode = ERR_INVALID_XML_FILE; /* +++ */
			return FALSE;
		}
		AddAttribute(pAttrs, t1.Value, t2.Value);
	}
	return TRUE;
}
  typename Miniball<CoordAccessor>::NT 
  Miniball<CoordAccessor>::suboptimality () const
  {
    NT* l = new NT[d+1];
    NT min_l = nt0;
    l[0] = NT(1);
    for (int i=ssize-1; i>0; --i) {
      l[i] = f[i];
      for (int k=ssize-1; k>i; --k)
	l[i]-=a[k][i]*l[k];
      if (l[i] < min_l) min_l = l[i];
      l[0] -= l[i];
    }
    if (l[0] < min_l) min_l = l[0];
    delete[] l;
    if (min_l < nt0)
      return -min_l;
    return nt0;
  }
void test_CV_volume(Polytope &HP, NT expected, NT tolerance=0.3)
{

    typedef typename Polytope::PolytopePoint Point;

    // Setup the parameters
    int n = HP.dimension();
    int walk_len=1;
    int nexp=1, n_threads=1;
    NT e=0.1, err=0.0000000001;
    NT C=2.0,ratio,frac=0.1,delta=-1.0;
    int rnum = std::pow(e,-2) * 400 * n * std::log(n);
    int N = 500 * ((int) C) + ((int) (n * n / 2));
    int W = 4*n*n+500;
    ratio = 1.0-1.0/(NT(n));
    unsigned seed = std::chrono::system_clock::now().time_since_epoch().count();
    RNGType rng(seed);
    boost::normal_distribution<> rdist(0,1);
    boost::random::uniform_real_distribution<>(urdist);
    boost::random::uniform_real_distribution<> urdist1(-1,1);

    //compute the chebychev ball
    std::pair<Point,NT> CheBall;


    // Estimate the volume
    std::cout << "Number type: " << typeid(NT).name() << std::endl;
    NT vol = 0;
    unsigned int const num_of_exp = 15;
    for (unsigned int i=0; i<num_of_exp; i++)
    {
        CheBall = HP.ComputeInnerBall();
        vars<NT, RNGType> var2(rnum,n,10 + n/10,n_threads,err,e,0,0,0,0,rng,
                 urdist,urdist1,-1.0,false,false,false,false,false,false,true,false);
        vars_g<NT, RNGType> var1(n,walk_len,N,W,1,e,CheBall.second,rng,C,frac,ratio,delta,false,
                    false,false,false,false,false,false,true,false);
        vol += volume_gaussian_annealing(HP, var1, var2, CheBall);
    }
    NT error = std::abs(((vol/num_of_exp)-expected))/expected;
    std::cout << "Computed volume (average) = " << vol/num_of_exp << std::endl;
    std::cout << "Expected volume = " << expected << std::endl;
            CHECK(error < tolerance);
}
예제 #14
0
Float ConjugateGradients::do_optimize(unsigned int max_steps) {
  IMP_OBJECT_LOG;
  IMP_USAGE_CHECK(get_model(),
                  "Must set the model on the optimizer before optimizing");
  clear_range_cache();
  Vector<NT> x, dx;
  int i;
  // ModelData* model_data = get_model()->get_model_data();

  FloatIndexes float_indices = get_optimized_attributes();

  int n = float_indices.size();
  if (n == 0) {
    IMP_THROW("There are no optimizable degrees of freedom.", ModelException);
  }

  x.resize(n);
  dx.resize(n);
  // get initial state in x(n):
  for (i = 0; i < n; i++) {
#ifdef IMP_CG_SCALE
    x[i] = get_scaled_value(float_indices[i]);  // scaled
#else
    x[i] = get_value(float_indices[i]);            // scaled
#endif
    IMP_USAGE_CHECK(
        !IMP::isnan(x[i]) && std::abs(x[i]) < std::numeric_limits<NT>::max(),
        "Bad input to CG");
  }

  // Initialize optimization variables
  int ifun = 0;
  int nrst;
  NT dg1, xsq, dxsq, alpha, step, u1, u2, u3, u4;
  NT f = 0., dg = 1., w1 = 0., w2 = 0., rtst, bestf;
  bool gradient_direction;

  // dx holds the gradient at x
  // search holds the search vector
  // estimate holds the best current estimate to the minimizer
  // destimate holds the gradient at the best current estimate
  // resy holds the restart Y vector
  // ressearch holds the restart search vector
  Vector<NT> search, estimate, destimate, resy, ressearch;
  search.resize(n);
  estimate.resize(n);
  destimate.resize(n);
  resy.resize(n);
  ressearch.resize(n);

/* Calculate the function and gradient at the initial
   point and initialize nrst,which is used to determine
   whether a Beale restart is being done. nrst=n means that this
   iteration is a restart iteration. */
g20:
  f = get_score(float_indices, x, dx);
  if (get_stop_on_good_score() &&
      get_scoring_function()->get_had_good_score()) {
    estimate = x;
    goto end;
  }
  ifun++;
  nrst = n;
  // this is a gradient, not restart, direction:
  gradient_direction = true;

  /* Calculate the initial search direction, the norm of x squared,
     and the norm of dx squared. dg1 is the current directional
     derivative, while xsq and dxsq are the squared norms. */
  dg1 = xsq = 0.;

  for (i = 0; i < n; i++) {
    search[i] = -dx[i];
    xsq += x[i] * x[i];
    dg1 -= dx[i] * dx[i];
  }
  dxsq = -dg1;

  /* Test if the initial point is the minimizer. */
  if (dxsq <= cg_eps * cg_eps * std::max(NT(1.0), xsq)) {
    goto end;
  }

/* Begin the major iteration loop. */
g40:
  update_states();
  /* Begin linear search. alpha is the steplength. */

  if (gradient_direction) {
    /* This results in scaling the initial search vector to unity. */
    alpha = 1.0 / sqrt(dxsq);
  } else if (nrst == 1) {
    /* Set alpha to 1.0 after a restart. */
    alpha = 1.0;
  } else {
    /* Set alpha to the nonrestart conjugate gradient alpha. */
    alpha = alpha * dg / dg1;
  }

  /* Store current best estimate for the score */
  estimate = x;
  destimate = dx;

  /* Try to find a better score by linear search */
  if (!line_search(x, dx, alpha, float_indices, ifun, f, dg, dg1, max_steps,
                   search, estimate)) {
    /* If the line search failed, it was either because the maximum number
       of iterations was exceeded, or the minimum could not be found */
    if (static_cast<unsigned int>(ifun) > max_steps) {
      goto end;
    } else if (gradient_direction) {
      goto end;
    } else {
      goto g20;
    }
  }

  /* THE LINE SEARCH HAS CONVERGED. TEST FOR CONVERGENCE OF THE ALGORITHM. */
  dxsq = xsq = 0.0;
  for (i = 0; i < n; i++) {
    dxsq += dx[i] * dx[i];
    xsq += x[i] * x[i];
  }
  if (dxsq < threshold_) {
    goto end;
  }

  /* Search continues. Set search(i)=alpha*search(i),the full step vector. */
  for (i = 0; i < n; i++) {
    search[i] *= alpha;
  }

  /* COMPUTE THE NEW SEARCH VECTOR;
     TEST IF A POWELL RESTART IS INDICATED. */
  rtst = 0.;
  for (i = 0; i < n; ++i) {
    rtst += dx[i] * destimate[i];
  }

  if (std::abs(rtst / dxsq) > .2) {
    nrst = n;
  }

  /* If a restart is indicated, save the current d and y
     as the Beale restart vectors and save d'y and y'y
     in w1 and w2. */
  if (nrst == n) {
    ressearch = search;
    w1 = w2 = 0.;
    for (i = 0; i < n; i++) {
      resy[i] = dx[i] - destimate[i];
      w1 += resy[i] * resy[i];
      w2 += search[i] * resy[i];
    }
  }

  /* CALCULATE THE RESTART HESSIAN TIMES THE CURRENT GRADIENT. */
  u1 = u2 = 0.0;
  for (i = 0; i < n; i++) {
    u1 -= ressearch[i] * dx[i] / w1;
    u2 += ressearch[i] * dx[i] * 2.0 / w2 - resy[i] * dx[i] / w1;
  }
  u3 = w2 / w1;
  for (i = 0; i < n; i++) {
    estimate[i] = -u3 * dx[i] - u1 * resy[i] - u2 * ressearch[i];
  }

  /* If this is a restart iteration, estimate contains the new search vector. */
  if (nrst != n) {

    /* NOT A RESTART ITERATION. CALCULATE THE RESTART HESSIAN
       TIMES THE CURRENT Y. */
    u1 = u2 = u3 = 0.0;
    for (i = 0; i < n; i++) {
      u1 -= (dx[i] - destimate[i]) * ressearch[i] / w1;
      u2 = u2 - (dx[i] - destimate[i]) * resy[i] / w1 +
           2.0 * ressearch[i] * (dx[i] - destimate[i]) / w2;
      u3 += search[i] * (dx[i] - destimate[i]);
    }
    step = u4 = 0.;
    for (i = 0; i < n; i++) {
      step =
          (w2 / w1) * (dx[i] - destimate[i]) + u1 * resy[i] + u2 * ressearch[i];
      u4 += step * (dx[i] - destimate[i]);
      destimate[i] = step;
    }

    /* CALCULATE THE DOUBLY UPDATED HESSIAN TIMES THE CURRENT
       GRADIENT TO OBTAIN THE SEARCH VECTOR. */
    u1 = u2 = 0.0;
    for (i = 0; i < n; i++) {
      u1 -= search[i] * dx[i] / u3;
      u2 +=
          (1.0 + u4 / u3) * search[i] * dx[i] / u3 - destimate[i] * dx[i] / u3;
    }
    for (i = 0; i < n; i++) {
      estimate[i] = estimate[i] - u1 * destimate[i] - u2 * search[i];
    }
  }

  /* CALCULATE THE DERIVATIVE ALONG THE NEW SEARCH VECTOR. */
  search = estimate;
  dg1 = 0.0;
  for (i = 0; i < n; i++) {
    dg1 += search[i] * dx[i];
  }

  /* IF THE NEW DIRECTION IS NOT A DESCENT DIRECTION,STOP. */
  if (dg1 <= 0.0) {

    /* UPDATE NRST TO ASSURE AT LEAST ONE RESTART EVERY N ITERATIONS. */
    if (nrst == n) {
      nrst = 0;
    }
    nrst++;
    gradient_direction = false;
    goto g40;
  }

/* ROUNDOFF HAS PRODUCED A BAD DIRECTION. */

end:
  // If the 'best current estimate' is better than the current state, return
  // that:
  bestf = get_score(float_indices, estimate, destimate);
  if (bestf < f) {
    f = bestf;
  } else {
    // Otherwise, restore the current state x (note that we already have the
    // state x and its derivatives dx, so it's rather inefficient to
    // recalculate the score here, but it's cleaner)
    f = get_score(float_indices, x, dx);
  }
  update_states();
  return f;
}
예제 #15
0
파일: line_e2.hpp 프로젝트: ghali/DelCapo
 void init_abc(const Point_E2<NT>& src, const Point_E2<NT>& tgt)
 {
     _a = + determinant(src.y(), NT(1.0), tgt.y(), NT(1.0));
     _b = - determinant(src.x(), NT(1.0), tgt.x(), NT(1.0));
     _c = + determinant(src.x(), src.y(), tgt.x(), tgt.y());
 }
예제 #16
0
파일: xer.c 프로젝트: poppe34/GRIP_STACK
flag Xer_DecodePrimitiveElement(ByteStream* pByteStrm, const char* elementTag, char* pDecodedValue, int *pErrCode) 
{
	Token t;
	char c = 0x0;

	strcpy(pDecodedValue,"");
	*pErrCode = ERR_INVALID_XML_FILE; /* +++ */

	if (NT(pByteStrm).TokenID != '<') {
		*pErrCode = ERR_INVALID_XML_FILE; /* +++ */
		return FALSE;
	}
	
	t = NT(pByteStrm);
	if ( (t.TokenID != WORD_ID) || (strcmp(t.Value ,elementTag)!=0)) {
		*pErrCode = ERR_INVALID_XML_FILE; /* +++ */
		return FALSE;
	}
	t = NT(pByteStrm);
	if (t.TokenID =='/') {
		if (NT(pByteStrm).TokenID == '>')
			return TRUE;
		else {
			*pErrCode = ERR_INVALID_XML_FILE; /* +++ */
			return FALSE;
		}
	} else {
		if (t.TokenID != '>') {
			*pErrCode = ERR_INVALID_XML_FILE; /* +++ */
			return FALSE;
		}
	}


/*
	t = NT(pByteStrm);
	strcpy(pDecodedValue, t.Value);
	if (t.TokenID != WORD_ID) {
		*pErrCode = ERR_INVALID_XML_FILE; 
		return FALSE;
	}
*/
	while(c!='<') 
	{
		if (!GetNextChar(pByteStrm, &c))
			return FALSE;
		if (c=='<') {
			*pDecodedValue = 0x0;
			pDecodedValue++;
			break;
		}

		*pDecodedValue = c;
		pDecodedValue++;
	}

	PushBackChar(pByteStrm);


	if (NT(pByteStrm).TokenID!='<') {
		*pErrCode = ERR_INVALID_XML_FILE; /* +++ */
		return FALSE;
	}

	if (NT(pByteStrm).TokenID!='/') {
		*pErrCode = ERR_INVALID_XML_FILE; /* +++ */
		return FALSE;
	}

	t = NT(pByteStrm);
	if ((t.TokenID != WORD_ID) || (strcmp(t.Value ,elementTag)!=0)) {
		*pErrCode = ERR_INVALID_XML_FILE; /* +++ */
		return FALSE;
	}

	if (NT(pByteStrm).TokenID!='>') {
		*pErrCode = ERR_INVALID_XML_FILE; /* +++ */
		return FALSE;
	}
	
	return TRUE;
}
예제 #17
0
inline std::vector<std::vector<NT> >
zero_matrix(const int d) {
  return std::vector<std::vector<NT> > (d, std::vector<NT>(d, NT(0)));
}
예제 #18
0
파일: main.cpp 프로젝트: spease/lr
int main(int const argc, char const * const * const argv)
{
  Grammar g;
  /*
  g |= NT("goal") >>= NT("expr");
  g |= NT("expr") >>= NT("term") + T("+") + NT("expr") | NT("term");
  g |= NT("term") >>= NT("factor") + T("*") + NT("term") | NT("factor");
  g |= NT("factor") >>= T("0") | T("1") | T("2") | T("3") | T("4") | T("5") | T("6") | T("7") | T("8") | T("9");
  */

  g |= NT("goal") >>= NT("expr");
  g |= NT("expr") >>= NT("term") + T("+") + NT("expr");
  g |= NT("expr") >>= NT("term");
  g |= NT("term") >>= NT("factor") + T("*") + NT("term");
  g |= NT("term") >>= NT("factor");
  g |= NT("factor") >>= T("id");

  /*
  g |= NT("E") >>= NT("E") + T("*") + NT("B");
  g |= NT("E") >>= NT("E") + T("+") + NT("B");
  g |= NT("E") >>= NT("B");
  g |= NT("B") >>= T("0");
  g |= NT("B") >>= T("1");
  */

  //g |= NT("B") >>= T("hello") + T(" ") + T("world") | T("goodbye") + T(" ") + T("world");

  /*
  g |= NT("start_$") >>= NT("start");
  g |= NT("start") >>= NT("start") + NT("expr");
  g |= NT("start");
  g |= NT("expr") >>= T("NR");
  g |= NT("expr") >>= NT("expr") + T("+") + NT("expr");
  */

  LRParser p(LRTable::Type::LR, 1, g);
  LexText plt(TEST_FILEPATH);
#ifndef NDEBUG
  std::cout << "====================----- Parsing -----====================" << std::endl;
#endif
  if(p.parse(plt))
  {
    std::cout << "Parsing success." << std::endl;
  }
#ifndef NDEBUG
  std::cout << "==================================================" << std::endl;
#endif

#ifndef NDEBUG
  std::cout << "====================----- " << TEST_FILEPATH << " -----====================" << std::endl;
  LexText lt(TEST_FILEPATH);
  Symbol s=END();
  do
  {
    s = lt.pop();
    std::cout << s.toString() << " ";
  }
  while(s != END());
  std::cout << std::endl;
  std::cout << "==================================================" << std::endl;

  
  std::cout << "====================----- Grammar -----====================" << std::endl;
  std::cout << g.toString();
  std::cout << "==================================================" << std::endl;
#endif

  return 0;
}
예제 #19
0
파일: lbrcb.c 프로젝트: rolk/ug
int NS_DIM_PREFIX BalanceGridRCB (MULTIGRID *theMG, int level)
{
  HEAP *theHeap = theMG->theHeap;
  GRID *theGrid = GRID_ON_LEVEL(theMG,level);       /* balance grid of level */
  LB_INFO *lbinfo;
  ELEMENT *e;
  int i, son;
  INT MarkKey;

  /* distributed grids cannot be redistributed by this function */
  if (me!=master && FIRSTELEMENT(theGrid) != NULL)
  {
    printf("Error: Redistributing distributed grids using recursive coordinate bisection is not implemented!\n");
    return (1);
  }

  if (me==master)
  {
    if (NT(theGrid) == 0)
    {
      UserWriteF("WARNING in BalanceGridRCB: no elements in grid\n");
      return (1);
    }

    Mark(theHeap,FROM_TOP,&MarkKey);
    lbinfo = (LB_INFO *)
             GetMemUsingKey(theHeap, NT(theGrid)*sizeof(LB_INFO), FROM_TOP, MarkKey);

    if (lbinfo==NULL)
    {
      Release(theHeap,FROM_TOP,MarkKey);
      UserWrite("ERROR in BalanceGridRCB: could not allocate memory from the MGHeap\n");
      return (1);
    }


    /* construct LB_INFO list */
    for (i=0, e=FIRSTELEMENT(theGrid); e!=NULL; i++, e=SUCCE(e))
    {
      lbinfo[i].elem = e;
      CenterOfMass(e, lbinfo[i].center);
    }


    /* apply coordinate bisection strategy */
    theRCB(lbinfo, NT(theGrid), 0, 0, DimX, DimY, 0);

    IFDEBUG(dddif,1)
    for (e=FIRSTELEMENT(theGrid); e!=NULL; e=SUCCE(e))
    {
      UserWriteF("elem %08x has dest=%d\n",
                 DDD_InfoGlobalId(PARHDRE(e)), PARTITION(e));
    }
    ENDDEBUG

    for (i=0, e=FIRSTELEMENT(theGrid); e!=NULL; i++, e=SUCCE(e))
    {
      InheritPartition (e);
    }

    Release(theHeap,FROM_TOP,MarkKey);
  }

  return 0;
}
예제 #20
0
NT unit_part_(const NT& x, CGAL::Integral_domain_without_division_tag){
    // For many other types the only units are just -1 and +1.
    return NT(int(CGAL::sign(x)));
}
예제 #21
0
void ArrangementDemoWindow::openDatFile( QString filename )
{
  int index = this->ui->tabWidget->currentIndex( );
  if ( index == -1 )
  {
    QMessageBox::information( this, "Oops", "Create a new tab first" );
    return;
  }
  if ( filename.isNull( ) )
  {
    return;
  }

  std::ifstream inputFile( filename.toStdString( ).c_str( ) );
  CGAL::Object arr = this->arrangements[ index ];
  Seg_arr* seg;
  Pol_arr* pol;

#ifdef CGAL_USE_CORE
  Conic_arr* conic;
#endif

  // Alg_seg_arr* alg;

  // Creates an ofstream object named inputFile
  if (! inputFile.is_open() ) // Always test file open
  {
    std::cerr << "Error opening input file" << std::endl;
    return;
  }

  Pol_traits traits;
  Pol_traits::Construct_curve_2 poly_const =
    traits.construct_curve_2_object();


  if ( CGAL::assign( pol, arr ) )
  {
    pol->clear( );

    std::vector<Arr_pol_point_2> points;

    unsigned int num_polylines;
    inputFile >> num_polylines;
    std::list<Arr_pol_2> pol_list;

    unsigned int i;
    for (i = 0; i < num_polylines; i++)
    {
      unsigned int num_segments;
      inputFile >> num_segments;
      points.clear();
      unsigned int j;
      for (j = 0; j < num_segments; j++)
      {
        int ix, iy;
        inputFile >> ix >> iy;
        points.push_back (Arr_pol_point_2(NT(ix),NT(iy)));
      }

      Arr_pol_2 curve = poly_const(points.begin(), points.end());
      pol_list.push_back(curve);
    }
    CGAL::insert(*pol, pol_list.begin(), pol_list.end());

    typedef ArrangementDemoTab< Pol_arr > TabType;
    TabType* tab = static_cast< TabType* >( this->tabs[ index ] );
    tab->setArrangement( pol );
  }
  else if ( CGAL::assign( seg, arr ) )