/**
	 \brief in the setup of this object, make a new system randomizer.
	 
	 \param solve_options the current state of the solver.
	 \param W input witness set, witn numbers of linears, patches, and variables.
	 */
	void make_randomizer(const SolverConfiguration & solve_options, const WitnessSet & W)
	{
		
		randomizer_ = std::make_shared<SystemRandomizer>(*(new SystemRandomizer));
		randomizer_->setup(W.num_variables()-W.num_linears()-W.num_patches(), solve_options.PPD.num_funcs);
		
	}
Example #2
0
void UbermasterProcess::critreal(WitnessSet & W, vec_mp *pi, VertexSet & V)
{
	
	
	
	SystemRandomizer randomizer;
	
	randomizer.setup(W.num_variables()-1-W.dimension(),solve_options.PPD.num_funcs);
	
	
	
	print_point_to_screen_matlab(pi[0],"pi");

	FILE *OUT;
	OUT = safe_fopen_write("most_recent_pi");
	
	print_vec_out_mp(OUT, pi[0]); /* Print vector to file */
	fclose(OUT);
	
	NullspaceConfiguration ns_config; // this is set up in the nullspace call.
	
	SolverOutput solve_out;
	
	
	
	
	compute_crit_nullspace_left(solve_out, // the returned value
						   W,            // input the original witness set
						   std::make_shared<SystemRandomizer>(randomizer),
						   pi,
						   W.dimension(),  // dimension of ambient complex object
						   W.dimension(),   //  target dimension to find
						   W.dimension(),   // COdimension of the critical set to find.
						   program_options,
						   solve_options,
						   &ns_config);
	
	
	WitnessSet W_crit, W_nonsing, W_sing;
	
	solve_out.get_noninfinite_w_mult_full(W_crit);
	solve_out.get_nonsing_finite_multone(W_nonsing);
	solve_out.get_sing_finite(W_sing);
	
	W_crit.write_dehomogenized_coordinates("crit_data");
	W_nonsing.write_dehomogenized_coordinates("nonsingular");
	W_sing.write_dehomogenized_coordinates("singular");
	
	
	
	return;
}
Example #3
0
void ns_concluding_modifications(SolverOutput & solve_out,
								 const WitnessSet & W,
								 NullspaceConfiguration * ns_config)
{
	solve_out.num_variables  = ns_config->num_natural_vars + ns_config->num_v_vars;
	solve_out.num_natural_vars = W.num_natural_variables();
	
	solve_out.add_patch(ns_config->v_patch);
	
	for (int ii=0; ii< ns_config->num_additional_linears; ii++) {
		solve_out.add_linear(ns_config->additional_linears_terminal[ii]);
	}
}
Example #4
0
void create_sliced_system(boost::filesystem::path input_file, boost::filesystem::path output_file,
                          vec_mp * linears, int num_to_add,
                          const WitnessSet & W)
{
#ifdef functionentry_output
	std::cout << "create_sliced_system" << std::endl;
#endif
	
	
	
	
	if (W.num_var_names()==0) {
		std::cout << "trying to create a sliced system, but witness set does not have the variable names." << std::endl;
		deliberate_segfault();
	}
	int *declarations = NULL;
	
	partition_parse(&declarations, input_file, "func_input", "config", 0); // the 0 means not self conjugate.
	free(declarations);
	
	FILE *OUT = safe_fopen_write(output_file);
	FILE *IN = safe_fopen_read("func_input");
	
	
	
	
	fprintf(OUT,"INPUT\n\n");
	copyfile(IN,OUT);
	fclose(IN);
	
	std::vector< int > indicators;
	for (int ii=0; ii<num_to_add; ii++) {
		indicators.push_back(rand());
	}
	
	for (int ii=0; ii<num_to_add; ii++) {
		std::stringstream linname;
		linname << "supp_lin_" << indicators[ii];
		write_vector_as_constants(linears[ii], linname.str(), OUT);
		
		linname.clear();  linname.str("");
	}
	
	for (int ii=0; ii<num_to_add; ii++) {
		fprintf(OUT,"function supp_lin_%d;\n",indicators[ii]);
	}
	for (int ii=0; ii<num_to_add; ii++) {
		fprintf(OUT,"supp_lin_%d = supp_lin_%d_1",indicators[ii],indicators[ii]);
		for (int jj=1; jj<W.num_variables(); jj++) {
			fprintf(OUT," + %s*supp_lin_%d_%d",W.name(jj).c_str(), indicators[ii],jj+1);
		}
		fprintf(OUT, ";\n\n");
	}
	fprintf(OUT,"END;\n\n\n\n");
	
    
    for (unsigned int ii=0; ii<W.num_patches(); ii++) {
		std::stringstream linname;
		linname << "patch_" << ii;
		write_vector_as_constants(W.patch(ii), linname.str(), OUT);
		linname.clear();  linname.str("");
	}
    
	fclose(OUT);
	
	
	
	
}
Example #5
0
void WitnessSet::merge(const WitnessSet & W_in, tracker_config_t * T)
{
	
	//error checking first
	if ( (num_vars_==0) && (W_in.num_vars_!=0) && (num_points()==0)) {
		num_vars_ = W_in.num_vars_;
		num_natty_vars_ = W_in.num_natty_vars_;
	}

	
	
	
	if (W_in.num_natty_vars_ != this->num_natty_vars_) {
		std::stringstream ss;
		ss << "merging two witness sets with differing numbers of natural variables. "<< W_in.num_natural_variables() <<" merging set, "<< this->num_natural_variables() << " existing\n",
		throw std::logic_error(ss.str());
	}
	
	//just mindlessly add the linears.  up to user to ensure linears get merged correctly.  no way to know what they want...
	for (unsigned int ii = 0; ii<W_in.num_linears(); ii++) {
		WitnessSet::add_linear(W_in.linear(ii));
	}
	
	
	for (unsigned int ii = 0; ii<W_in.num_points(); ii++) {
		int is_new = 1;
		vec_mp & in_point = W_in.point(ii);
		for (unsigned int jj = 0; jj<num_points(); jj++){
			vec_mp & curr_point = this->point(jj);
			
			//cache the sizes
			int in_size = in_point->size;
			int curr_size = curr_point->size;
			
			
			in_point->size = this->num_natural_variables();
			curr_point->size = this->num_natural_variables();
			
			if (isSamePoint_homogeneous_input(curr_point, in_point, T->final_tol_times_mult)) {
				is_new = 0;
				
				in_point->size = in_size;
				curr_point->size = curr_size;
				break;
			}
			
			// restore the sizes
			in_point->size = in_size;
			curr_point->size = curr_size;
		}
		
		if (is_new==1)
			WitnessSet::add_point( (in_point) );
	}
	
	
	for (unsigned int ii = 0; ii<W_in.num_patches(); ii++) {
		int is_new = 1;
		
		for (unsigned int jj = 0; jj<this->num_patches(); jj++){
			if ( this->patch(jj)->size ==  W_in.patch(ii)->size) {
				if (isSamePoint_inhomogeneous_input(patch(jj), W_in.patch(ii), T->final_tol_times_mult)) {
					is_new = 0;
					break;
				}
			}
		}
		
		if (is_new==1)
			WitnessSet::add_patch(W_in.patch(ii));
	}
	
	
	
	return;
}//re: merge_witness_sets
Example #6
0
void nullspace_config_setup_right(NullspaceConfiguration *ns_config,
								  vec_mp *pi, // an array of projections, the number of which is the target dimensions
								  int ambient_dim,
								  int *max_degree, // a pointer to the value
								  std::shared_ptr<SystemRandomizer> randomizer,
								  const WitnessSet & W,
								  SolverConfiguration & solve_options)
{
	
	ns_config->set_side(nullspace_handedness::RIGHT);
	
	
	
	int toss;
	parse_input_file(W.input_filename(), &toss); // re-create the parsed files for the stuffs (namely the SLP).
	
	ns_config->set_randomizer(randomizer); // set the pointer.  this randomizer is for the underlying system.
	
	*max_degree = randomizer->max_degree()-1; // minus one for differentiated degree
	ns_config->max_degree = *max_degree;
	
	
	
	// set some integers
	
	ns_config->num_projections = ambient_dim;
	
	ns_config->num_v_vars = W.num_natural_variables()-1;
	
	
	ns_config->num_synth_vars = W.num_synth_vars(); // this may get a little crazy if we chain into this more than once.  this code is written to be called into only one time beyond the first.
	ns_config->num_natural_vars = W.num_natural_variables();
	
	ns_config->ambient_dim = ambient_dim;
	
	
	ns_config->target_projection = (vec_mp *) br_malloc(ns_config->num_projections * sizeof(vec_mp));
	for (int ii=0; ii<ns_config->num_projections; ii++) {
		init_vec_mp2(ns_config->target_projection[ii], W.num_variables(),solve_options.T.AMP_max_prec);
		ns_config->target_projection[ii]->size = W.num_variables();
		vec_cp_mp(ns_config->target_projection[ii], pi[ii]);
	}
	
	
	
	ns_config->num_jac_equations = (ns_config->num_natural_vars - 1);// N-1;  the subtraction of 1 is for the 1 hom-var.
																	 // me must omit any previously added synthetic vars.
	
	ns_config->num_additional_linears = ambient_dim-1;
	
	ns_config->num_v_linears = ns_config->num_jac_equations;
	
	
	
	// this check is correct.
	int check_num_func = randomizer->num_rand_funcs() + ns_config->num_jac_equations + ns_config->num_additional_linears + W.num_patches() + 1; // +1 for v patch from this incoming computation
	int check_num_vars = ns_config->num_natural_vars + ns_config->num_synth_vars + ns_config->num_v_vars;
	if (check_num_func != check_num_vars) {
		std::cout << color::red();
		std::cout << "mismatch in number of equations...\n" << std::endl;
		std::cout << "left: " << check_num_func << " right " << check_num_vars << std::endl;
		std::cout << color::console_default();
		throw std::logic_error("logic error in nullspace_left");
	}
	
	

	
	
	
	// set up the linears in $v$  ( the M_i linears)
	ns_config->v_linears = (vec_mp *)br_malloc(ns_config->num_v_linears*sizeof(vec_mp));
	for (int ii=0; ii<ns_config->num_v_linears; ii++) {
		init_vec_mp2(ns_config->v_linears[ii],ns_config->num_v_vars,solve_options.T.AMP_max_prec);
		ns_config->v_linears[ii]->size = ns_config->num_v_vars;
		for (int jj=0; jj<ns_config->num_v_vars; jj++){
			get_comp_rand_mp(&ns_config->v_linears[ii]->coord[jj]); // should this be real? no.
		}
	}
	
	
	// the last of the linears will be used for the slicing, and passed on to later routines
	int offset = 1;
	
	
	ns_config->additional_linears_terminal = (vec_mp *)br_malloc((ns_config->num_additional_linears)*sizeof(vec_mp));
	ns_config->additional_linears_starting = (vec_mp *)br_malloc((ns_config->num_additional_linears)*sizeof(vec_mp));
	
	for (int ii=0; ii<ns_config->num_additional_linears; ii++) {
		init_vec_mp2(ns_config->additional_linears_terminal[ii],W.num_variables(),solve_options.T.AMP_max_prec);
		ns_config->additional_linears_terminal[ii]->size = W.num_variables();
		
		for (int jj=0; jj<W.num_natural_variables(); jj++){
			get_comp_rand_mp(&ns_config->additional_linears_terminal[ii]->coord[jj]); // should this be real?  no.
		}
		for (int jj=W.num_natural_variables(); jj<W.num_variables(); jj++) {
			set_zero_mp(&ns_config->additional_linears_terminal[ii]->coord[jj]);
		}
		
		
		init_vec_mp2(ns_config->additional_linears_starting[ii],W.num_variables(),solve_options.T.AMP_max_prec);
		ns_config->additional_linears_starting[ii]->size = W.num_variables();
		vec_cp_mp(ns_config->additional_linears_starting[ii], W.linear(ii+offset));
	}
	
	
	// set up the patch in $v$.  we will include this in an inversion matrix to get the starting $v$ values.
	init_vec_mp2(ns_config->v_patch,ns_config->num_v_vars,solve_options.T.AMP_max_prec);
	ns_config->v_patch->size = ns_config->num_v_vars;
	for (int ii=0; ii<ns_config->num_v_vars; ii++) {
		get_comp_rand_mp(&ns_config->v_patch->coord[ii]);
	}
	
	
	
	mat_mp temp_getter;  init_mat_mp2(temp_getter,0, 0,solve_options.T.AMP_max_prec);
	temp_getter->rows = 0; temp_getter->cols = 0;
	
	
	
	//the 'ns_config->starting_linears' will be used for the x variables.  we will homotope to these 1 at a time
	ns_config->starting_linears = (vec_mp **)br_malloc( randomizer->num_rand_funcs()*sizeof(vec_mp *));
	for (int ii=0; ii<randomizer->num_rand_funcs(); ii++) {
		
		int curr_degree = std::max(0,randomizer->randomized_degree(ii)-1);
		
		
		ns_config->starting_linears[ii] = (vec_mp *) br_malloc(curr_degree*sizeof(vec_mp));
		
		make_matrix_random_mp(temp_getter,curr_degree, W.num_natural_variables(), solve_options.T.AMP_max_prec); // this matrix is nearly orthogonal
		
		for (unsigned int jj=0; jj<curr_degree; jj++) {
			init_vec_mp2(ns_config->starting_linears[ii][jj],W.num_variables(),solve_options.T.AMP_max_prec);
			ns_config->starting_linears[ii][jj]->size = W.num_variables();
			
			for (int kk=0; kk<W.num_natural_variables(); kk++) {
				set_mp(&ns_config->starting_linears[ii][jj]->coord[kk], &temp_getter->entry[jj][kk]);
			}
			
			for (int kk=W.num_natural_variables(); kk<W.num_variables(); kk++) {
				set_zero_mp(&ns_config->starting_linears[ii][jj]->coord[kk]);
			}
		}
		
	}
	
	
	clear_mat_mp(temp_getter);
	
	
	
	return;
}
Example #7
0
int compute_crit_nullspace_right(SolverOutput & solve_out, // the returned value
						   const WitnessSet & W,
						   std::shared_ptr<SystemRandomizer> randomizer,
						   vec_mp *pi, // an array of projections, the number of which is the target dimensions
						   int ambient_dim,
						   BertiniRealConfig & program_options,
						   SolverConfiguration & solve_options,
						   NullspaceConfiguration *ns_config)
{
	//many of the 1's here should be replaced by the number of patch equations, or the number of variable_groups
	
	
	
	
	
	// get the max degree of the derivative functions.  this is unique to the left nullspace formulation, as the functions become mixed together
	int max_degree;
	
	
	nullspace_config_setup_right(ns_config,
						   pi,
						   ambient_dim,
						   &max_degree,
						   randomizer,
						   W,
						   solve_options);
	
	
	
	
	
	if (max_degree==0) {
		// this will probably need tweaking when the dimension is higher than 1.  but who really is going to decompose a linear surface?
		solve_out.copy_patches(W);
		ns_concluding_modifications(solve_out, W, ns_config);
		
		
		std::cout << "the highest degree of any derivative equation is 0.  Returning empty SolverOutput." << std::endl;
		//then there cannot possibly be any critical points, with respect to ANY projection.  simply return an empty but complete set.
		
		return 0;
	}
	
	
	
	
	
	
	//
	///
	/////        end setup
	////////
	//////////////
	///////////////////////////
	
	
	
	
	
	
	int offset;
	WitnessSet Wtemp, Wtemp2;
	
	
	//  2.  Do a bunch of homotopies in $x$, each set of which will be followed by a single linear solve in $v$.
	if (program_options.verbose_level()>=3) {
		std::cout << "building up linprod start system for left nullspace" << std::endl;
	}
	
	// setup for the multilin moves
	//  these are for feeding into the multilin solver -- and that's it.  the majority will be overridden in the while loop as the start x linears
	vec_mp *multilin_linears = (vec_mp *) br_malloc(W.num_linears()*sizeof(vec_mp)); // target dim is the number of linears in the input witness set
	for (unsigned int ii=0; ii<W.num_linears(); ii++) {
		init_vec_mp2(multilin_linears[ii],W.num_variables(), solve_options.T.AMP_max_prec);
		multilin_linears[ii]->size = W.num_variables();
		vec_cp_mp(multilin_linears[ii], W.linear(ii));
	}
	
	MultilinConfiguration ml_config(solve_options,randomizer);
	
	
	
	// this is for performing the matrix inversion to get ahold of the $v$ values corresponding to $x$
	mat_mp tempmat;  init_mat_mp2(tempmat, ns_config->num_v_vars, ns_config->num_v_vars,solve_options.T.AMP_max_prec);
	tempmat->rows = tempmat->cols = ns_config->num_v_vars;
	
	offset = ns_config->num_v_vars-1;
	for (int jj=0; jj<ns_config->num_v_vars; jj++)
		set_mp(&tempmat->entry[offset][jj], &ns_config->v_patch->coord[jj]);
	
	
	// for holding the result of the matrix inversion
	vec_mp result; init_vec_mp2(result,ns_config->num_v_vars,solve_options.T.AMP_max_prec);  result->size = ns_config->num_v_vars;
	
	// use this for the matrix inversion
	vec_mp invert_wrt_me;
	init_vec_mp2(invert_wrt_me,ns_config->num_v_vars,solve_options.T.AMP_max_prec); invert_wrt_me->size = ns_config->num_v_vars;
	for (int ii=0; ii<ns_config->num_v_vars-1; ii++)
		set_zero_mp(&invert_wrt_me->coord[ii]); // set zero
	
	set_one_mp(&invert_wrt_me->coord[ns_config->num_v_vars-1]); // the last entry is set to 1 for the patch equation
	
	
	
	
	
	
	vec_mp temppoint;  init_vec_mp2(temppoint, ns_config->num_natural_vars +ns_config->num_synth_vars + ns_config->num_v_vars,solve_options.T.AMP_max_prec);
	temppoint->size = ns_config->num_natural_vars + ns_config->num_synth_vars + ns_config->num_v_vars;
	
	
	WitnessSet W_step_one;
	W_step_one.set_num_variables(W.num_variables());
	W_step_one.set_num_natural_variables(W.num_natural_variables());
	W_step_one.copy_patches(W);
	W_step_one.copy_names(W);
	
	
	WitnessSet W_linprod;
	W_linprod.set_num_variables(ns_config->num_natural_vars + ns_config->num_v_vars + ns_config->num_synth_vars);
	W_linprod.set_num_natural_variables(W.num_natural_variables());
	
	
	if (program_options.quick_run()<=1)
		solve_options.robust = true;
	else
		solve_options.robust = false;
	
	
	
	
	
	for (int ii=0; ii<randomizer->num_rand_funcs(); ii++) {
		
		int differentiated_degree = randomizer->randomized_degree(ii)-1; // the -1 is for differentiating.  this could be 0.
		
		if (differentiated_degree==0) {
			continue;
		}
		else{
			for (int jj=0; jj<differentiated_degree; jj++) {
				
				//copy in the linear for the solve
				vec_cp_mp(multilin_linears[0], ns_config->starting_linears[ii][jj]);
				
				// the remainder of the linears are left alone (stay stationary).
				
				if (program_options.verbose_level()>=6) {
					std::cout << "moving FROM this set:\n";
					for (unsigned int ii=0; ii<W.num_linears(); ii++) {
						print_point_to_screen_matlab(W.linear(ii),"L");
					}
					std::cout << "\nTO this set:\n";
					for (unsigned int ii=0; ii<W.num_linears(); ii++) {
						print_point_to_screen_matlab(multilin_linears[ii],"ELL");
					}
				}
				
				
				
				// actually solve WRT the linears
				
				
				SolverOutput fillme;
				multilin_solver_master_entry_point(W,         // WitnessSet
												   fillme, // the new data is put here!
												   multilin_linears,
												   ml_config,
												   solve_options);
				
				WitnessSet Wtemp;
				fillme.get_noninfinite_w_mult_full(Wtemp); // should be ordered
				
				W_step_one.merge(Wtemp, &solve_options.T);
				
				Wtemp.reset();
			}
			
			
			
			int curr_index = 0;
			for (int kk=0; kk<ns_config->num_v_vars; kk++) { // subtract one from upper limit because of the patch equation
				if (kk!=ii) {
					
					for (int mm=0; mm<ns_config->num_v_vars; mm++){
						set_mp(&tempmat->entry[curr_index][mm], &ns_config->v_linears[kk]->coord[mm]);}
					
					curr_index++;
				}
			}
			
			
			// invert the matrix for the v variables.
			matrixSolve_mp(result, tempmat,  invert_wrt_me);
			
			//set the bottom part of the temppoint, which will be a startpoint for the nullspace call later.
			offset = ns_config->num_natural_vars+ns_config->num_synth_vars;
			for (int mm=0; mm<ns_config->num_v_vars; mm++)
				set_mp(&temppoint->coord[mm+offset], &result->coord[mm]);
			
			
			//set the top part, x, of the start point, and copy it in.
			for (unsigned int kk=0; kk<W_step_one.num_points(); kk++) {
				for (int mm=0; mm<ns_config->num_natural_vars+ns_config->num_synth_vars; mm++) {
					set_mp(&temppoint->coord[mm], & W_step_one.point(kk)->coord[mm]);
				}
				W_linprod.add_point(temppoint);
			}
			
			
			
			W_step_one.reset();
			W_step_one.set_num_variables(W.num_variables());
			W_step_one.set_num_natural_variables(W.num_natural_variables());
			W_step_one.copy_patches(W);  // necessary?
			W_step_one.copy_names(W); // necessary?
		}
		
		
		
		
		
		
		
	}
	
	
	for (int ii=0; ii<1; ii++)
		clear_vec_mp(multilin_linears[ii]);
	free(multilin_linears);
	
	clear_vec_mp(temppoint);
	
	
	
	int num_before = W_linprod.num_points();
	W_linprod.sort_for_unique(&solve_options.T);
	if (num_before - W_linprod.num_points()>0) {
		std::cout << "there were non-unique start points" << std::endl;
		mypause();
	}
	
	
	
	W_linprod.set_num_natural_variables(ns_config->num_v_vars+ns_config->num_synth_vars);
	W_linprod.copy_patches(W);
	W_linprod.copy_names(W);
	
	//set some solver options
	
	if (program_options.quick_run()<=0)
		solve_options.robust = true;
	else
		solve_options.robust = false;
	
	
	
	solve_options.use_midpoint_checker = 0;
	
	
	
	if (program_options.verbose_level()>=6)
		ns_config->print();
	
	
	
	if (program_options.verbose_level()>=3) {
		std::cout << "running nullspace right method" << std::endl;
	}
	
	
	
	
	nullspacejac_solver_master_entry_point(solve_options.T.MPType,
										   W_linprod, // carries with it the start points, but not the linears.
										   solve_out,   // the created data goes in here.
										   ns_config,
										   solve_options);
	
	
	ns_concluding_modifications(solve_out, W, ns_config);
	
	
	clear_mat_mp(tempmat);
	clear_vec_mp(invert_wrt_me);
	clear_vec_mp(result);
	
	
	return SUCCESSFUL;
}
Example #8
0
int UbermasterProcess::main_loop()
{
	
	boost::timer::auto_cpu_timer t;
	
	
	program_options.splash_screen();
	
	
	//parse the options
	program_options.startup(); // tests for existence of necessary files, etc.
	
	//if desired, display the options
	if (program_options.verbose_level()>=3)
		program_options.display_current_options();
	
	
	
	
	parse_preproc_data("preproc_data", &solve_options.PPD);
	
	
	
	int num_vars = get_num_vars_PPD(solve_options.PPD);
	
	
	NumericalIrreducibleDecomposition witness_data;
	witness_data.populate(&solve_options.T);
	

	WitnessSet W = witness_data.choose(program_options);
	
	if (W.num_points()==0) {
		std::cout << "no witness points, cannot decompose anything..." << std::endl;
		return 1;
	}
	
	
	
	
	W.get_variable_names(num_vars);
	W.set_input_filename(program_options.input_filename());
	
	
		
	
	if (program_options.verbose_level()>=1) {
		W.print_to_screen();
	}
	
	
	
	
	
	
	VertexSet V(num_vars);
	
	V.set_tracker_config(&solve_options.T);
	
	V.set_same_point_tolerance(1e1*solve_options.T.real_threshold);

	
	vec_mp *pi = (vec_mp *) br_malloc(W.dimension()*sizeof(vec_mp ));
	for (int ii=0; ii<W.dimension(); ii++) {
		init_vec_mp2(pi[ii],W.num_variables(), solve_options.T.AMP_max_prec);
		pi[ii]->size = W.num_variables();
	}
	get_projection(pi, program_options, W.num_variables(), W.dimension());
	
    for (int ii=0; ii<W.dimension(); ii++) {
        V.add_projection(pi[ii]);
    }
    
	
	if (program_options.primary_mode()==BERTINIREAL) {
		bertini_real(W,pi,V);
		
	}
	else if(program_options.primary_mode()==CRIT)
	{
		critreal(W,pi,V);
	}
	
	
	

	
	
	for (int ii=0; ii<W.dimension(); ii++)
		clear_vec_mp(pi[ii]);
	free(pi);
	
	
	// dismiss the workers
	int sendme = TERMINATE;
	MPI_Bcast(&sendme, 1, MPI_INT, 0, MPI_COMM_WORLD);
	return SUCCESSFUL;
}
Example #9
0
void UbermasterProcess::bertini_real(WitnessSet & W, vec_mp *pi, VertexSet & V)
{
	
	
	W.set_incidence_number(get_incidence_number( W.point(0), program_options, program_options.input_filename()));

	boost::filesystem::path temp_name = program_options.output_dir();
	std::stringstream converter;
	converter << "_dim_" << W.dimension() << "_comp_" << W.component_number();
	temp_name += converter.str();
	
	program_options.output_dir(temp_name);
	
	
	
	
	switch (W.dimension()) {
		case 1:
		{
			Curve C;
		
			// curve
			C.main(V, W, pi, program_options, solve_options);
			
			if (program_options.verbose_level()>=2)
				printf("outputting data\n");
			
			
			
			
			C.output_main(program_options.output_dir());
			
			V.print(program_options.output_dir()/ "V.vertex");
			
		}
			break;
			
			
		case 2:
		{
			
			
			Surface S;
			
			// surface
			S.main(V, W, pi, program_options, solve_options);
			
			
			
			
			S.output_main(program_options.output_dir());
			
			V.print(program_options.output_dir()/ "V.vertex");
		}
			break;
			
		default:
		{
			std::cout << "bertini_real not programmed for components of dimension " << W.dimension() << std::endl;
		}
			break;
	}
	
}
int sphere_solver_master_entry_point(const WitnessSet						&W, // carries with it the start points, and the linears.
									 SolverOutput							&solve_out, // new data goes in here
									 SphereConfiguration &		config,
									 SolverConfiguration		& solve_options)
{
	
	if (solve_options.use_parallel()) {
		solve_options.call_for_help(SPHERE_SOLVER);
	}
	
	sphere_eval_data_d *ED_d = NULL;
	sphere_eval_data_mp *ED_mp = NULL;
	
	
	switch (solve_options.T.MPType) {
		case 0:
			ED_d = new sphere_eval_data_d(0);
			
			ED_d->setup(config,
						W,
						solve_options);
			break;
			
		case 1:
			ED_mp = new sphere_eval_data_mp(1);
			
			ED_mp->setup(config,
						 W,
						 solve_options);
//			// initialize latest_newton_residual_mp
//			mpf_init(solve_options.T.latest_newton_residual_mp);   //    <------ THIS LINE IS ABSOLUTELY CRITICAL TO CALL
			break;
		case 2:
			ED_d = new sphere_eval_data_d(2);
			
			ED_mp = ED_d->BED_mp;
			
			
			ED_d->setup(config,
						W,
						solve_options);
			
			
			
			adjust_tracker_AMP(& (solve_options.T), W.num_variables());
			
			break;
		default:
			break;
	}
	
	
	
	master_solver(solve_out, W,
                  ED_d, ED_mp,
                  solve_options);
	
	
	
	switch (solve_options.T.MPType) {
		case 0:
			delete ED_d;
			break;
			
		case 1:
			delete ED_mp;
			break;
			
		case 2:
			delete ED_d;
			break;
		default:
		{
			std::stringstream printme;
			printme << "trying to use an MPType which is not 0, 1, or 2.  yours is " << solve_options.T.MPType << std::endl;
			throw std::logic_error(printme.str());
			break;
		}
	}
	
	
	for (unsigned int jj=0; jj<W.num_linears(); jj++)
	{
		solve_out.add_linear(W.linear(jj));
	}
	
	return SUCCESSFUL;
	
}
int sphere_eval_data_d::setup(SphereConfiguration & config,
							  const WitnessSet & W,
							  SolverConfiguration & solve_options)
{
	
	SLP_memory = config.SLP_memory;
	
	// set up the vectors to hold the two linears.
	
	
	mp_to_d(radius, config.radius);
	vec_mp_to_d(center, config.center);
    
    if (this->center->size < W.num_variables()) {
        int old_size = this->center->size;
        increase_size_vec_d(this->center, W.num_variables());
        this->center->size = W.num_variables();
        
        for (int ii=old_size; ii<W.num_variables(); ii++) {
            set_zero_d(&this->center->coord[ii]);
        }
    }
    
    
	if (this->num_static_linears==0) {
		static_linear = (vec_d *) br_malloc(W.num_linears()*sizeof(vec_d));
	}
	else
	{
		static_linear = (vec_d *) br_realloc(static_linear, W.num_linears()*sizeof(vec_d));
	}
	
	for (unsigned int ii=0; ii<W.num_linears(); ii++) {
		init_vec_d(static_linear[ii],0);
		vec_mp_to_d(static_linear[ii],W.linear(ii));
	}
	num_static_linears = W.num_linears();
	
    num_natural_vars = W.num_natural_variables();
	num_variables = W.num_variables();
	
	
	
	for (int ii=0; ii<2; ii++) {
		vec_mp_to_d(starting_linear[ii],config.starting_linear[ii]);
	}
	
	verbose_level(solve_options.verbose_level());
	
	SolverDoublePrecision::setup(config.SLP, config.randomizer());
	
	generic_setup_patch(&patch,W);
	
	if (solve_options.use_gamma_trick==1)
		get_comp_rand_d(this->gamma); // set gamma to be random complex value
	else
		set_one_d(this->gamma);
	
	
	
	
	if (this->MPType==2)
	{
		this->BED_mp->setup(config, W, solve_options);
		rat_to_d(this->gamma, this->BED_mp->gamma_rat);
	}
	
	return 0;
}
int sphere_eval_data_mp::setup(SphereConfiguration & config,
							   const WitnessSet & W,
							   SolverConfiguration & solve_options)
{
	
	
	if (config.randomizer().use_count()==0) {
		std::cout << "don't have randomizer set up!" << std::endl;
		br_exit(-97621);
	}
	
	if (!config.have_mem) {
		std::cout << "don't have memory!" << std::endl;
		br_exit(-3231);
	}
	
	this->SLP_memory = config.SLP_memory;
	
	num_natural_vars = W.num_natural_variables();
	num_variables = W.num_variables();
	
	
	// set up the vectors to hold the linears.
	if (this->num_static_linears==0) {
		static_linear = (vec_mp *) br_malloc(W.num_linears()*sizeof(vec_mp));
	}
	else
	{
		static_linear = (vec_mp *) br_realloc(static_linear, W.num_linears()*sizeof(vec_mp));
	}
	
	for (unsigned int ii=0; ii<W.num_linears(); ii++) {
		init_vec_mp(static_linear[ii],0);
		vec_cp_mp(static_linear[ii],W.linear(ii));
	}
	
	
	
	set_mp(this->radius, config.radius);
	vec_cp_mp(this->center, config.center);
	if (this->center->size < W.num_variables()) {
        int old_size = this->center->size;
        increase_size_vec_mp(this->center, W.num_variables());
        this->center->size = W.num_variables();
        
        for (int ii=old_size; ii<W.num_variables(); ii++) {
            set_zero_mp(&this->center->coord[ii]);
        }
    }
    
    
	if (this->MPType==2) {
		
		set_mp(this->radius_full_prec, config.radius);
		vec_cp_mp(this->center_full_prec, config.center);
        if (this->center_full_prec->size < W.num_variables()) {
            int old_size = this->center_full_prec->size;
            increase_size_vec_mp(this->center_full_prec, W.num_variables());
            this->center_full_prec->size = W.num_variables();
            
            for (int ii=old_size; ii<W.num_variables(); ii++) {
                set_zero_mp(&this->center_full_prec->coord[ii]);
            }
        }
        
        
		
		if (this->num_static_linears==0) {
			static_linear_full_prec = (vec_mp *) br_malloc(W.num_linears()*sizeof(vec_mp));
		}
		else
		{
			static_linear_full_prec = (vec_mp *) br_realloc(static_linear_full_prec, W.num_linears()*sizeof(vec_mp));
		}
		
		for (unsigned int ii=0; ii<W.num_linears(); ii++) {
			init_vec_mp2(static_linear_full_prec[ii],0,1024);
			
			vec_cp_mp(static_linear_full_prec[ii], W.linear(ii));
		}
	}
	
	this->num_static_linears = W.num_linears();
	
	
	
	
	
	for (int ii=0; ii<2; ii++) {
		vec_cp_mp( this->starting_linear[ii], config.starting_linear[ii]);
		
		if (MPType==2) {
			vec_cp_mp(this->starting_linear_full_prec[ii], config.starting_linear[ii]);
		}
	}
	
	
	
	
	
	// the usual
	
	verbose_level(solve_options.verbose_level());
	
	SolverMultiplePrecision::setup(config.SLP, config.randomizer());
	
	generic_setup_patch(&patch,W);
	
	if (solve_options.use_gamma_trick==1)
		get_comp_rand_mp(this->gamma); // set gamma to be random complex value
	else{
		set_one_mp(this->gamma);
	}
	
	comp_d temp;
	if (this->MPType==2) {
		if (solve_options.use_gamma_trick==1){
			get_comp_rand_rat(temp, this->gamma, this->gamma_rat, 64, solve_options.T.AMP_max_prec, 0, 0);
		}
		else{
			set_one_mp(this->gamma);
			set_one_rat(this->gamma_rat);
		}
	}
	
	

	
	return 0;
}