Beispiel #1
0
z3::expr Polynomial::toZ3expr(char** name, z3::context& c) const {
	char** pname = name;
	if (pname == NULL) {
		pname = new char*[Nv];
		for (int i = 0; i < Nv; i++) {
			pname[i] = new char[8];
			sprintf(pname[i], "x%d", i);
		}
	}

	std::vector<z3::expr> x;
	for (int i = 0; i < Nv; i++) {
		x.push_back(c.real_const(pname[i]));
	}

	std::vector<z3::expr> theta;
	char real[65];
	for (int i = 0; i < dims; i++) {
		snprintf(real, 64, "%2.8f", this->theta[i]);
		theta.push_back(c.real_val(real));
	}

	z3::expr expr = theta[0];
	for (int i = 1; i < dims; i++) {
		z3::expr tmp = theta[i];
		for (int j = 0; j < Nv; j++) {
			int power = vparray[i][j];
			while (power-- > 0) {
				tmp = tmp * x[j];
			}
		}
		expr = expr + tmp;
	}

	//std::cout << "expr1: " << expr1 << std::endl;
	//std::cout << "expr2: " << expr2 << std::endl;

	z3::expr hypo = expr >= 0;
	if (name == NULL) {
		for (int i = 0; i < Nv; i++) {
			delete[]pname[i];
		}
		delete[]pname;
	}
	x.clear();
	theta.clear();
	return hypo;
}
Beispiel #2
0
    // FIXME : remake copy constructor
    z3ann(const z3ann &ann) :
        _equationId(0),
        _inputSize(ann._inputSize),
        _hiddenSize(ann._hiddenSize),
        _outputSize(ann._outputSize),
        _precision(ann._precision),
        _linkTable(_inputSize + _hiddenSize + _outputSize),
        _solver(_context)
    {
        int totalSizeNode = _inputSize + _hiddenSize + _outputSize;
        std::vector<std::vector<z3::expr*> >::iterator it;
        std::vector<z3::expr*>::iterator iit;
        std::stringstream ss;
        std::string str;
        int i;
        int j;

        _weights.resize(totalSizeNode);
        for (it = _weights.begin(), i = 0; it != _weights.end(); ++it, ++i)
            for (iit = it->begin(), j = 0; iit != it->end(); ++iit, ++j)
                {
                    ss.clear();
                    ss << i;
                    ss << "_";
                    ss << j;
                    str = "w";
                    str += ss.str();
                    *iit = new z3::expr(_context.real_const(str.c_str()));
                }

    }
Beispiel #3
0
z3::expr getBigAnd(std::vector<z3::expr>& v, z3::context& ctx) {
  auto res = ctx.bool_val(true);
  if (v.empty())
    return res;
  res = v[0];
  for (auto i = 1; i < v.size(); ++i)
    res = res && v[i];
  return res;
}
Beispiel #4
0
    z3ann(int inputSize, int hiddenSize, int outputSize,
          float min = -1, float max = 1,
          int precision = DEFAULTPRECISION) :
        _equationId(0),
        _inputSize(inputSize),
        _hiddenSize(hiddenSize),
        _outputSize(outputSize),
        _precision(precision),
        _min(min),
        _max(max),
        _isSolved(false),
        _linkTable(inputSize + hiddenSize + outputSize),
        _solver(_context)
    {
        int totalSizeNode = _inputSize + _hiddenSize + _outputSize;
        std::stringstream ss;
        std::string str;
        int i;
        int j;

        _weights.resize(totalSizeNode);
        _realWeights.resize(totalSizeNode);
        for (i = 0; i < totalSizeNode; ++i)
            {
                _weights[i].resize(totalSizeNode);
                _realWeights[i].resize(totalSizeNode);
                for (j = 0; j < totalSizeNode; ++j)
                    {
                        ss.clear();
                        ss.str(std::string());
                        ss << i;
                        ss << "_";
                        ss << j;
                        str = "w";
                        str += ss.str();
                        _weights[i][j] = new z3::expr(_context.real_const(str.c_str()));
                        _realWeights[i][j] = 0.f;
                    }
            }
    }