Beispiel #1
0
std::vector<int> karatsuba(const std::vector<int> &a, const std::vector<int> &b)
{
	// a = a2 * k^n + a1
	// b = b2 * k^n + b1
	// a * b = (a2 * b2) * k^2n + (a2 * b1 + a1 * b2) * k^n + (a1 * b1)
	//       = (a2 * b2) * k^2n + ((a1 + a2) * (b1 + b2) - (a2 * b2) - (a1 * b1)) * k^n + (a1 * b1)
	//        = z0 * k^2n + z2 * k^n + z1
	// z0 = a2 * b2
	// z1 = a1 * b1

	if (a.size() < b.size())
		return karatsuba(b, a);
	if (b.size() == 0)
		return std::vector<int>();

	//if (a.size() <= 50)
	//	return multiply(a, b);

	if (a.size() < 3)
		return multiply(a, b);

	size_t half = a.size() / 2;
	size_t b_half = std::min(half, size_t(b.end() - b.begin()));

	std::vector<int> a1(a.begin(), a.begin() + half);
	std::vector<int> a2(a.begin() + half, a.end());
	std::vector<int> b1(b.begin(), b.begin() + b_half);
	std::vector<int> b2(b.begin() + b_half, b.end());

	std::vector<int> z0 = karatsuba(a2, b2);
	std::vector<int> z1 = karatsuba(a1, b1);

	std::vector<int> a3 = a1;
	addTo(a3, a2, 0);
	std::vector<int> b3 = b1;
	addTo(b3, b2, 0);
	std::vector<int> z2 = karatsuba(a3, b3);
	subFrom(z2, z0, 0);
	subFrom(z2, z1, 0);

	std::vector<int> ret;
	ret.reserve(a.size() + b.size());
	addTo(ret, z1, 0);
	addTo(ret, z2, half);
	addTo(ret, z0, half * 2);

	normalize(ret);
	return ret;
}
Beispiel #2
0
    virtual TTimePoint step() override
    {
        ClockBase::step();

        current_ = addTo(current_, step_);
        return current_;
    }
Beispiel #3
0
void Obstacle::on_addToScene()
{
    node_ = SceneGraph::addModel(name_, model_);
    size_t batchCnt = 0;
    TriangleBatch const *triBatch = model_->batches(&batchCnt);
    size_t boneCnt = 0;
    Bone const *bone = model_->bones(&boneCnt);
    size_t vSize = model_->vertexSize();
    char const * vertex = (char const *)model_->vertices();
    unsigned int const *index = (unsigned int const *)model_->indices();
    for (size_t bi = 0; bi != batchCnt; ++bi)
    {
        dTriMeshDataID tmd = dGeomTriMeshDataCreate();
        dGeomTriMeshDataBuildSingle(tmd, vertex, vSize, triBatch[bi].maxVertexIndex + 1, 
            index + triBatch[bi].firstTriangle * 3, triBatch[bi].numTriangles * 3, 12);
        dGeomID geom = dCreateTriMesh(gStaticSpace, tmd, 0, 0, 0);
        tmd_.push_back(tmd);
        geom_.push_back(geom);
        Matrix bx;
        get_bone_transform(bone, triBatch[bi].bone, bx);
        Vec3 p(bx.translation());
        addTo(p, pos());
        dGeomSetPosition(geom, p.x, p.y, p.z);
        dGeomSetRotation(geom, bx.rows[0]);
    }
}
Beispiel #4
0
template<class R, class N, class K, int n> void TreeInNode<R, N, K, n>::addTo(R* root) {
	if (root) {
		addTo(*root);
	} else {
		remove();
	}
}
Beispiel #5
0
Action::Action( QWidget *pParent, const char *pName, const QString &pDisplayName,
                QObject *pTarget, const char *pActivateSlot,
                QWidget *pAddTo, bool pEnabled,
                const QPixmap &pIcon, QWidget *pToolBar,
                const QString &pToolTip ) :
 QAction(pDisplayName, pParent)
{
  setObjectName(pName);
  _name = pName;
  _displayName = pDisplayName;
  _toolTip = pToolTip;

  QString hotkey = _preferences->parent(pName);
  if (!hotkey.isNull() && !_hotkeyList.contains(hotkey))
  {
    _hotkeyList << hotkey;
    setShortcutContext(Qt::ApplicationShortcut);
    if (hotkey.left(1) == "C")
      setShortcut(QString("Ctrl+%1").arg(hotkey.right(1)));

    else if (hotkey.left(1) == "F")
      setShortcut(hotkey);
  }

  connect(this, SIGNAL(activated()), pTarget, pActivateSlot);
  setEnabled(pEnabled);
  pAddTo->addAction(this);
  setIconSet(QIcon(pIcon));
  addTo(pToolBar);
  setToolTip(_toolTip);
}
Beispiel #6
0
std::vector<int>* sum(std::vector<std::vector<int>*>* entries) {
	std::vector<int>* vectorRep = new std::vector<int>();
	std::vector<std::vector<int>*>::iterator eit;
	for (eit = entries->begin(); eit != entries->end(); eit++) {
		std::vector<int>* v = *eit;
		addTo(vectorRep, v);
	}
	return vectorRep;
}
Beispiel #7
0
 void dfs(int& min_cost, int& cost, vector<int>& cart, vector<int>& needs, vector<vector<int>>& special, vector<int>& price) {
     if (overfit(cart, needs)) return;
     
     for (int i = 0; i < special.size(); ++i) {
         auto offer = special[i];
         addTo(cart, offer, cost, price, min_cost, needs, i);
         dfs(min_cost, cost, cart, needs, special, price);
         removeFrom(cart, offer, cost, i);
     }
 }
Beispiel #8
0
void Barrel::calcPhys(Model *m)
{
    Vec3 lob(m->lowerBound());
    Vec3 upb(m->upperBound());
    center_ = lob;
    addTo(center_, upb);
    scale(center_, 0.5f);
    subFrom(upb, lob);
    radius_ = std::max(upb.x, upb.y) * 0.5f;
    height_ = upb.z;
}
Beispiel #9
0
Action::Action( QWidget *pParent, const char *pName, const QString &pDisplayName,
                QObject *pTarget, const char *pActivateSlot,
                QWidget *pAddTo, const QString & pEnabled,
                const QPixmap &pIcon, QWidget *pToolBar ) :
 QAction(pDisplayName, pParent)
{
  init(pParent, pName, pDisplayName, pTarget, pActivateSlot, pAddTo, pEnabled);

  setIconSet(QIcon(pIcon));
  addTo(pToolBar);
}
ToolBarItem::ToolBarItem( QWidget *parent, QWidget *toolBar,
			  const QString &label, const QString &tagstr,
			  const QIconSet &icon, const QKeySequence &key )
    : QAction( parent )
{
    setIconSet( icon );
    setText( label );
    setAccel( key );
    addTo( toolBar );
    tag = tagstr;
    connect( this, SIGNAL( activated() ), this, SLOT( wasActivated() ) );
}
Beispiel #11
0
Action::Action( QWidget *pParent, const char *pName, const QString &pDisplayName,
                QObject *pTarget, const char *pActivateSlot,
                QWidget *pAddTo, bool pEnabled,
                const QPixmap &pIcon, QWidget *pToolBar,
                const QString &pToolTip ) :
 QAction(pDisplayName, pParent)
{
  init(pParent, pName, pDisplayName, pTarget, pActivateSlot, pAddTo, (pEnabled?"true":"false"));

  _toolTip = pToolTip;

  setIconSet(QIcon(pIcon));
  addTo(pToolBar);
  setToolTip(_toolTip);
}
Beispiel #12
0
//=====================================
// XOpenGL Constructor...
//-------------------------------------
XOpenGL::XOpenGL (XFrame* xf,XIntro* xi) : XTemplate(xf,xi) {
	mCheck3DStatusChanged = false;
	addTo (xf,xi);
}
Beispiel #13
0
void SceneManager::addOtherRole(IRole *role)
{
	if (role == mainRole) return;
	addTo(ROLE_LAYER, role);
	_roles.push_back(role);
}
Beispiel #14
0
Node &Node::operator+=(const IntLeaf &leaf) {
	return addTo(leaf);
};
Beispiel #15
0
 explicit RightToLeftClick(QObject * parent = nullptr) : QObject{parent} {
     addTo(parent);
 }
Beispiel #16
0
//=====================================
// XTablet Constructor...
//-------------------------------------
XTablet::XTablet (XFrame* xf,XIntro* xi) : XTemplate(xf,xi) {
	deleteOnly = false;
    addTo (xf,xi);
}
Beispiel #17
0
bool Optimize::eval_grad_f(Ipopt::Index n, const Ipopt::Number *x, bool new_x, Ipopt::Number *grad_f)
{
    assert(n == n_variables);
    UNUSED(new_x);
    if (updateCross(x) == false) return false;
    Ipopt::Number t1[3], t2[3], t[3], e[3], f[3], tmp;
    Ipopt::Number* pV;
    PointArrayEdit pf = grad_f;
    PointArray px = x;
    setZeros(grad_f, n);
    int idx;
    int i = 0, size = EnergyVertices.size();
    for (; i < size; i++)
    {
        computeEF(i, x, e, f);
        tmp = EdgesLengthProduct[i] + dot(e,f);
        tmp *= tmp;
        tmp = 4 * pOp->BendingEnergyCoef * EdgesLengthProduct[i]/ VerticesWeight[i] / tmp;
        idx = idxPrevVertex[i];
        multiplyByScale(f, tmp, t1);
        if (idx >= 0)
            addTo(t1, pf(idx));
        multiplyByScale(e, -tmp, t2);
        idx = idxNextVertex[i];
        if (idx >= 0)
            addTo(t2, pf(idx));
        idx = idxTheVertex[i];
        if (idx >= 0)
        {
            add(t1, t2, t);
            multiplyByScaleTo(t, -1, pf(idx));
        }
    }
    i = 0;
    size = PositionConstraints.size();
    for (; i < size; i++)
    {
        idx = PositionConstraints[i];
        pV = positions[i].data();
        sub(px(idx), pV, t);
        multiplyByScaleTo(t, 2 * pOp->PositionConstraintsWeight, pf(idx));
    }
    i = 0;
    size = TangentConstraints.size();
    for (; i < size; ++i)
    {
        pV = tangents[i].data();
        idx = TangentConstraints[i].first;
        if (idx >= 0)
            multiplyByScaleTo(pV, pOp->TangentConstraintsCoef, pf(idx));
        idx = TangentConstraints[i].second;
        if (idx >= 0)
            multiplyByScaleTo(pV, -pOp->TangentConstraintsCoef, pf(idx));
    }

    Point P;
    i = 0;
    size = PlaneConstraints.size();
    for (; i < size; ++i)
    {
        idx = PlaneConstraints[i];
        P = PlaneConstraintsInfo[i].first;
        tmp = 2 * ((P | getPoint(idx, x)) + PlaneConstraintsInfo[i].second);
        multiplyByScaleTo(P.data(), tmp * pOp->PlaneConstraintsCoef, pf(idx));
    }
    return true;
}
Beispiel #18
0
//=====================================
// XAccessX Constructor...
//-------------------------------------
XAccessX::XAccessX (XFrame* xf,XIntro* xi) : XTemplate(xf,xi) {
    addTo (xf,xi);
}
 /**
  * @brief Add a new node to an existing
  * @details this function create an edge and a node
  * @param addedLabel label of the new node
  * @param label label of the existing node
  * @param edgeWeight weight of the new edge
  * @return creation of the edge was successful
  */
 virtual bool addTo(const Label_t& addedLabel, const Label_t& label,
     const Weight_t& edgeWeight = Weight_t()) {
   return addTo(addedLabel, Weight_t(), label, edgeWeight);
 }
Beispiel #20
0
 TTimePoint stepBy(TTimeDelta amount)
 {
     current_ = addTo(current_, amount);
     return current_;
 }