Exemple #1
0
void Scale::show(std::ostream &out) const {
  Particle *p = get_particle();
  bool hasupper = p->has_attribute(get_upper_key());
  out << get_lower() << " < ";
  out << " Scale = " << get_nuisance();
  if (hasupper) out << " < " << get_upper();
}
IMPISD_BEGIN_NAMESPACE

void Switching::show(std::ostream &out) const {
  out << get_lower() << " < ";
  out << " Switching = " << get_nuisance();
  out << " < " << get_upper();
}
Exemple #3
0
char get_l_d()
{
	int i = get_rand(36);
	if (i < 26)
		return get_lower();
	else
		return get_digit();
}
Exemple #4
0
char get_letter()
{
	int i = get_rand(2);
	if (i < 1)
		return get_lower();
	else
		return get_upper();
}
void build_white_opening_book()
    {
    struct tree_type *root;
    short bb[64],x,value;
    unsigned char blk[14],tp[64],t[64];
    long size,posit=0,wps=0,bps=0;
    FILE *h1,*h2;

    root=init_obook_tree();
    if(!root) fatal_error("Not enough memory, darn!");

    h1=fopen(DATABASEFILE,"rb");
    if(!h1) fatal_error("Data Base error!");

    size=fileln(h1);
    if(size%14!=0) fatal_error("Opening book file is corrupted");

    printf("Loading and sorting opening book...\n");

    while(size>0)
        {
        fread(blk,1,12,h1);
        expand_block(blk,t);

        for(x=0;x<64;x++)
            bb[x]=t[x];

        get_lower(bb,tp);
        collapse_position(tp,blk);

        blk[12]=getc(h1);
        blk[13]=getc(h1);

        if(posit>0) insert_obook_tree(blk,root);
        else memcpy(root->position,blk,14);

        if(blk[13]==0) wps++;
        else bps++;

        posit++;
        size-=14;
        }

    fclose(h1);

    printf("Flushing out ordered opening book...\n");

    h2=fopen(WHITE_BOOK,"wb");
    if(!h2) fatal_error("Cannot write output file!");

    flush_out_obtree(root,h2);

    free_obook_tree(root);
    fclose(h2);

    printf("Positions for white %ld; positions for black %ld\n\n",wps,bps);
    }
Exemple #6
0
char get_letter_digit()
{
	int i = get_rand(62);
	if (i < 26)
		return get_upper();
	else if (i >= 26 && i < 52)
		return get_lower();
	else
		return get_digit();
}
void Nuisance::set_nuisance(Float d) {
    Float d_=d;
    Particle *p=get_particle();
    if (has_lower())
    {
        Float lo = get_lower();
        if (d < lo)  d_ = lo;
    }
    if (has_upper())
    {
        Float up = get_upper();
        if (d > up)  d_ = up;
    }
    p->set_value(get_nuisance_key(), d_);
}
Exemple #8
0
        double Brent::minimize(const func1d& func, const int maxiter, const double tol)
        {
            static const double CGOLD = 0.3819660;
            static const double ZEPS  = 1.0e-12;
            double d, e;
            d = e = 0.0;

            double ax = get_lower();
            double bx = get_mid();
            double cx = get_upper();

            double a, b;
            a = ax < cx ? ax : cx;
            b = ax > cx ? ax : cx;

            double x, w, v;
            x = w = v = bx;

            double fx, fw, fv;
            fx = fw = fv = func(x);

            for(int it=0; it<maxiter; it++) {
                double xm = 0.5 * (a + b);
                double tol1 = tol * abs(x) + ZEPS;
                double tol2 = 2.0 * tol1;
                
                // �I—¹”»’è
                if(abs(x - xm) <= (tol2 - 0.5 * (b - a))) {
                    break;
                }

                // ‘o‹È�ü•âŠÔ
                if(abs(e) > tol1) {
                    double r = (x - w) * (fx - fv);
                    double q = (x - v) * (fx - fw);
                    double p = (x - v) * q - (x - w) * r;
                    q = 2.0 * (q - r);
                    if(q > 0.0) {
                        p = -p;
                    }
                    q = abs(q);
                    double etemp = e;
                    e = d;
                    if(abs(p) >= abs(0.5 * q * etemp) || p <= q * (a - x) || p >= q * (b - x)) {
                        e = x >= xm ? a - x : b - x;
                        d = CGOLD * e;
                    }
                    else {
                        d = p / q;
                        double u = x + d;
                        if(u - a < tol2 || b - u < tol2) {
                            d = sgn(xm - x) * tol1;
                        }
                    }
                }
                else {
                    e = x >= xm ? a - x : b - x;
                    d = CGOLD * e;
                }
                double u = abs(d) >= tol1 ? x + d : x + sgn(d) * tol1;
                double fu = func(u);

                if(fu <= fx) {
                    if(u >= x) {
                        a = x;
                    } else {
                        b = x;
                    }
                    shift3(v, w, x, u);
                    shift3(fv, fw, fx, fu);
                }
                else {
                    if(u < x) {
                        a = u;
                    } else {
                        b = u;
                    }
                    if(fu <= fw || w == x) {
                        v = w;
                        w = u;
                        fv = fw; 
                        fw = fu;
                    } else if(fu <= fv || v == x || v == w) {
                        v = u;
                        fv = fu;
                    }
                }
            }

            fmin = fx;
            xmin = x;
            return xmin;        
        }