Exemplo n.º 1
0
static double sc(basis_s *v,simplex *s, int k, int j) {
/* amount by which to scale up vector, for reduce_inner */

	double		labound;
	static int	lscale;
	static double	max_scale,
			ldetbound,
			Sb;

	if (j<10) {
		labound = logb(v->sqa)/2;
		max_scale = exact_bits - labound - 0.66*(k-2)-1  -DELIFT;
		if (max_scale<1) {
			warning(-10, overshot exact arithmetic);
			max_scale = 1;

		}

		if (j==0) {
			int	i;
			neighbor *sni;
			basis_s *snib;

			ldetbound = DELIFT;

			Sb = 0;
			for (i=k-1,sni=s->neigh+k-1;i>0;i--,sni--) {
				snib = sni->basis;
				Sb += snib->sqb;
				ldetbound += logb(snib->sqb)/2 + 1;
				ldetbound -= snib->lscale;
			}
		}
	}
	if (ldetbound - v->lscale + logb(v->sqb)/2 + 1 < 0) {
		DEBS(-2)
			DEBTR(-2) DEBEXP(-2, ldetbound)
			print_simplex_f(s, DFILE, &print_neighbor_full);
			print_basis(DFILE,v);
		EDEBS			
		return 0;					
	} else {
Exemplo n.º 2
0
int main( int argc, char * argv[] )
{
    // degree of polinomial parametrization
    // warning: not set N to a value greater than 20!
    // (10 in case you don't utilize the micro-basis)
    // determinant computation becomes very expensive
    unsigned int N = 4;
    // max modulus of polynomial coefficients
    unsigned int M = 1000;

    if (argc > 1)
        N = std::atoi(argv[1]);
    if (argc > 2)
        M = std::atoi(argv[2]);

    Geom::SL::MVPoly1 f, g;
    Geom::SL::basis_type b;
    Geom::SL::MVPoly3 p, q;
    Geom::SL::Matrix<Geom::SL::MVPoly2> B;
    Geom::SL::MVPoly2 r;

    // generate two univariate polynomial with degree N
    // and coeffcient in the range [-M, M]
    f = pick_multipoly_max<1>(N, M);
    g = pick_multipoly_max<1>(N, M);

    std::cout << "parametrization: \n";
    std::cout << "f = " << f << std::endl;
    std::cout << "g = " << g << "\n\n";

    // computes the micro-basis
    microbasis(b, f, g);
    // in case you want utilize directly the initial basis
    // you should uncomment the next row and comment
    // the microbasis function call
    //make_initial_basis(b, f, g);

    std::cout << "generators in vector form : \n";
    print_basis(b);
    std::cout << std::endl;

    // micro-basis generators
    basis_to_poly(p, b[0]);
    basis_to_poly(q, b[1]);

    std::cout << "generators as polynomial in R[t,x,y] : \n";
    std::cout << "p = " << p << std::endl;
    std::cout << "q = " << q << "\n\n";

    // make up the Bezout matrix and compute the determinant
    B = make_bezout_matrix(p, q);
    r = determinant_minor(B);
    r.normalize();

    std::cout << "Bezout matrix: (entries are bivariate polynomials) \n";
    std::cout << "B = " << B << "\n\n";
    std::cout << "determinant: \n";
    std::cout << "r(x, y) = " << r << "\n\n";

    return EXIT_SUCCESS;
}
Exemplo n.º 3
0
int optimize_transport(BASIS *basis)
{
	/** Declare |optimize_transport| scalars */

	int i_enter,j_enter;
	int arcindex;
	int halfnodes;
	int subroot;
	int prev;
	int orient;		
	int status;
	double deltadual;		


	/** Declare |optimize_transport| arrays */

	int *family;
	int *pred;
	int *brother;
	int *son;




	status=init_basis(basis);  /* construct initial basis */
	if (status) return status; 

	/** Define simplifications for |optimize_transport| */

	family = basis->family;
	pred = basis->pred;
	brother = basis->brother;
	son = basis->son;



	halfnodes=basis->no_nodes/2;

	deltadual=find_entering_arc(basis,&i_enter,&j_enter,&arcindex); 

	while(i_enter>=0){		/* there is an entering arc  */

		basis->pivot++;		

#ifdef PRINT
		printf("+-----------------------------------+\n");
		printf("|            pivot %3d              |\n",basis->pivot);
		printf("+-----------------------------------+\n");
#endif

		subroot = find_cycle(basis,i_enter,j_enter,arcindex,&orient);

#ifdef PRINT
		printf("\nentering arc : %d  --> %d \n",i_enter,j_enter);
		printf("    arcindex : %d\n",arcindex);
		printf("     redcost : %8.4lf",deltadual);
#endif

		/* update duals in the smaller subtrees */
		if(family[subroot]<=halfnodes)
			update_dual(basis,subroot,(orient>0)?deltadual:-deltadual);
		else { /* separate trees, update duals, then reconnect */
			basis->rerooted++;
			prev = pred[subroot];
			/* remove root from successors of prev */
			son[prev]= brother[subroot];

			update_dual(basis,0,(orient>0)?-deltadual:deltadual);

			brother[subroot]=son[prev];      /* insert root to successors of prev */
			son[prev]=subroot;
		}

#ifdef PRINT    
		print_basis(basis);
#endif 

		deltadual=find_entering_arc(basis,&i_enter,&j_enter,&arcindex);
	}

	status=check_solution(basis);

	return status;  
}