/** get the index of the variable or returns number of variables
     if the index is not found */
 size_t var_location(size_t var_id) const {
   size_t location = num_vars();
   for(size_t i = 0; i < num_vars() && !(location < num_vars()); ++i) {
     if(_vars[i].id() == var_id) location = i;
   }
   return location;
 }
Пример #2
0
NcBool NcFile::sync( void )
{
    if (!data_mode())
      return 0;
    if (NcError::set_err(
			 nc_sync(the_id)
			 ) != NC_NOERR)
      return 0;
    int i;
    for (i = 0; i < num_dims(); i++) {
	if (dimensions[i]->is_valid()) {
	    dimensions[i]->sync();
	} else {		// someone else added a new dimension
	    dimensions[i] = new NcDim(this,i);
	}
    }
    for (i = 0; i < num_vars(); i++) {
	if (variables[i]->is_valid()) {
	    variables[i]->sync();
	} else {		// someone else added a new variable
	    variables[i] = new NcVar(this,i);
	}
    }
    return 1;
}
 void set_asg(size_t var_id, size_t value) {
   size_t idx = var_location(var_id);
   assert(idx < num_vars());
   assert(value < var(idx).size());
   _asgs[idx] = value;
   recompute_linear_index();
 }
 //! Recompute the discrete_assignments from the index
 void recompute_asgs() {
   size_t quotient = _index;
   for(size_t i = 0; i < num_vars(); ++i) {
     _asgs[i] = quotient % _vars[i].size();
     quotient /= _vars[i].size();
     // assert(_asgs[i] < _args.var(i).size());
   }
 }
 //! Recompute the index from the discrete_assignment
 void recompute_linear_index() {
   size_t multiple = 1;
   // Clear the index
   _index = 0;
   for(size_t i = 0; i < num_vars(); ++i) {
     _index += multiple * _asgs[i];
     //        assert(_args.var(i).nasgs > 0);
     multiple *= _vars[i].size();
   }
 }
Пример #6
0
 // throws exception if contains unbounded variable
 void check_unbounded() {
     unsigned num = num_vars();
     for (var x = 0; x < num; x++) {
         if (m_lower[x] == INT_MIN || m_upper[x] == INT_MAX)
             throw_not_supported();
         // possible extension: support bound normalization here
         if (m_lower[x] != 0) 
             throw_not_supported(); // use bound normalizer
     }
 }
Пример #7
0
/*
 * Name and size of the problem + core settings
 * and construction_time
 */
static void print_problem_size(FILE *f, smt_core_t *core, char *filename, double construction_time) {
  fprintf(f, "Problem: %s\n\n", basename(filename));
  fprintf(f, "Construction time       : %.4f s\n", construction_time);
  fprintf(f, "nb. of vars             : %"PRIu32"\n", num_vars(core));
  fprintf(f, "nb. of unit clauses     : %"PRIu32"\n", num_unit_clauses(core));
  fprintf(f, "nb. of bin clauses      : %"PRIu32"\n", num_binary_clauses(core));
  fprintf(f, "nb. of big clauses      : %"PRIu32"\n", num_prob_clauses(core));
  fprintf(f, "clause decay            : %g\n", clause_decay_factor(core));
  fprintf(f, "var decay               : %g\n", var_decay_factor(core));
  fprintf(f, "randomness factor       : %g\n\n", randomness_factor(core));
}
    /** Makes the sub_domain the first set of variables to be incremented over
     * Can only be called once
     */
    void transpose_to_start(const discrete_domain<MAX_DIM>& sub_domain) {
      ASSERT_FALSE(transposed);
      transposed = true;
        
      size_t reorder_map[MAX_DIM];
      size_t cursubdomain_idx = 0;
      size_t remainder_idx = sub_domain.num_vars();
      for (size_t i = 0;i < num_vars(); ++i) {
        if (cursubdomain_idx < sub_domain.num_vars() && 
            _vars[i].id() == sub_domain.var(cursubdomain_idx).id()) {
          reorder_map[cursubdomain_idx] = i;
          ++cursubdomain_idx;
        }
        else {
          reorder_map[remainder_idx] = i;
          ++remainder_idx;
        }
      }
      //move the asg around

        
      uint16_t newasgs[MAX_DIM];
      size_t newincrement_step[MAX_DIM]; 
      discrete_variable newvars[MAX_DIM];
      for (size_t i = 0;i < num_vars() ; ++i) {
        newincrement_step[i] = _increment_step[reorder_map[i]];
        newasgs[i] = _asgs[reorder_map[i]];
        newvars[i] = _vars[reorder_map[i]];
      }
      // copyback
      for (size_t i = 0;i < num_vars(); ++i) {
        _asgs[i] = newasgs[i];
        _vars[i] = newvars[i];
        _increment_step[i] = newincrement_step[i];
      }
    } // end of transpose_to_start
 //! Get the next fast_discrete_assignment
 fast_discrete_assignment& operator++() {
   // Update the discrete_assignments
   for(size_t i = 0; i < num_vars(); ++i) {
     if (_asgs[i] < (_vars[i].size() - 1)) {
       _asgs[i] = (_asgs[i] + 1);
       _index += _increment_step[i];
       return *this;
     }
     else {
       _index -= _asgs[i] * _increment_step[i];
       _asgs[i] = 0;
     }
   }
   // Reached end
   make_end();
   return *this;
 }
Пример #10
0
/*
 * All atoms
 */
void print_egraph_atoms(FILE *f, egraph_t *egraph) {
  smt_core_t *core;
  uint32_t v, n;
  void *atm;

  core = egraph->core;
  if (core != NULL) {
    n = num_vars(core);
    for (v=0; v<n; v++) {
      atm = bvar_atom(core, v);
      if (atm != NULL && atom_tag(atm) == EGRAPH_ATM_TAG) {
        print_egraph_atom(f, egraph, untag_atom(atm));
        fputc('\n', f);
      }
    }
  }
}
Пример #11
0
NcBool NcFile::close( void )
{
    int i;
    
    if (the_id == ncBad)
      return 0;
    for (i = 0; i < num_dims(); i++)
      delete dimensions[i];
    for (i = 0; i < num_vars(); i++)
      delete variables[i];
    delete [] dimensions;
    delete [] variables;
    delete globalv;
    int old_id = the_id;
    the_id = ncBad;
    return NcError::set_err(
			    nc_close(old_id)
			    ) == NC_NOERR;
}
Пример #12
0
NcVar* NcFile::add_var(NcToken name, NcType type, int ndims, const NcDim** dims)
{
    if (!is_valid() || !define_mode())
      return 0;
    int* dimids = new int[ndims];
    for (int i=0; i < ndims; i++)
      dimids[i] = dims[i]->id();
    int n = num_vars();
    int varid;
    if(NcError::set_err(
			nc_def_var(the_id, name, (nc_type) type, ndims, dimids, &varid)
			) != NC_NOERR)
	return 0;
    NcVar* varp =
      new NcVar(this, varid);
    variables[n] = varp;
    delete [] dimids;
    return varp;
}
Пример #13
0
NcVar* NcFile::add_var(NcToken name, NcType type, // scalar to 5D var
			    const NcDim* dim0,
			    const NcDim* dim1,
			    const NcDim* dim2,
			    const NcDim* dim3,
			    const NcDim* dim4)
{
    if (!is_valid() || !define_mode())
      return 0;
    int dims[5];
    int ndims = 0;
    if (dim0) {
	ndims++;
	dims[0] = dim0->id();
	if (dim1) {
	    ndims++;
	    dims[1] = dim1->id();
	    if (dim2) {
		ndims++;
		dims[2] = dim2->id();
		if (dim3) {
		    ndims++;
		    dims[3] = dim3->id();
		    if (dim4) {
			ndims++;
			dims[4] = dim4->id();
		    }
		}
	    }
	}
    }
    int n = num_vars();
    int varid;
    if(NcError::set_err(
			nc_def_var(the_id, name, (nc_type) type, ndims, dims, &varid)
			) != NC_NOERR)
	return 0;
    NcVar* varp =
      new NcVar(this, varid);
    variables[n] = varp;
    return varp;
}
Пример #14
0
NcVar* NcFile::get_var( int i ) const
{
    if (! is_valid() || i < 0 || i >= num_vars())
      return 0;
    return variables[i];
}
Пример #15
0
NcFile::NcFile( const char* path, FileMode fmode, 
		size_t* chunksizeptr, size_t initialsize, FileFormat fformat  )
{
    NcError err(NcError::silent_nonfatal); // constructor must not fail

    int mode = NC_NOWRITE;
    the_fill_mode = Fill;
    int status;
    
    // If the user wants a 64-bit offset format, set that flag.
    if (fformat == Offset64Bits)
       mode |= NC_64BIT_OFFSET;
#ifdef USE_NETCDF4
    else if (fformat == Netcdf4)
       mode |= NC_NETCDF4;
    else if (fformat == Netcdf4Classic)
       mode |= NC_NETCDF4|NC_CLASSIC_MODEL;
#endif

    switch (fmode) {
    case Write:
	mode |= NC_WRITE;
	/*FALLTHRU*/
    case ReadOnly:
	// use netcdf-3 interface to permit specifying tuning parameter
	status = NcError::set_err(
				  nc__open(path, mode, chunksizeptr, &the_id)
				  );
	if(status != NC_NOERR)
	{
	    NcError::set_err(status);
	    the_id =  -1;
	}
	in_define_mode = 0;
	break;
    case New:
	mode |= NC_NOCLOBBER;
	/*FALLTHRU*/
    case Replace:
	// use netcdf-3 interface to permit specifying tuning parameters
	status = NcError::set_err(
				  nc__create(path, mode, initialsize,
				      chunksizeptr, &the_id)
				  );
	if(status != NC_NOERR)
	{
	    NcError::set_err(status);
	    the_id =  -1;
	}
	in_define_mode = 1;
	break;
    default:
	the_id = ncBad;
	in_define_mode = 0;
	break;
    }
    if (is_valid()) {
	dimensions = new NcDim*[NC_MAX_DIMS];
	variables = new NcVar*[NC_MAX_VARS];
	int i;
	for (i = 0; i < num_dims(); i++)
	    dimensions[i] = new NcDim(this, i);
	for (i = 0; i < num_vars(); i++)
	    variables[i] = new NcVar(this, i);
	globalv = new NcVar(this, ncGlobal);
    } else {
	dimensions = 0;
	variables = 0;
	globalv = 0;
    }
}
 size_t asg(size_t var_id) const {
   size_t idx = var_location(var_id);
   assert(idx < num_vars());
   return _asgs[idx];
 }
Пример #17
0
size_t FSTestSettings::fs_dim() {
    return num_dimensions() + num_vars();
}