long __Call_primes( CDSR_VMEval& vm, MMD_Address& addr, UniWord *arg ) { #if _DEBUG if( addr.param2 < 0 ) throw _T("__Call_(fun) : internal error, out of range"); #endif #ifndef _NO_HMATHBS CDSRArray<CDSRNatural> res; if( addr.param2 == 0 ) // 1 arg { CDSRNatural nV( (arg - 1)->getNatural() ); ::EratosfenACM( nV, res ); *(arg - 1) = vm.getSmbTable().makeUniWord_Vector( res ); } else // 2 arg { CDSRNatural nV1( (arg - 2)->getNatural() ); CDSRNatural nV2( (arg - 1)->getNatural() ); ::EratosfenRange( nV1, nV2, res ); *(arg - 2) = vm.getSmbTable().makeUniWord_Vector( res ); } #endif return 1 - addr.param3; }
void CliquePartitionProblem::gradient(IndexedList const & v, DoubleVector & result) const { ASSERT_CHECK(v.max_size()==nV()); result.assign(v.max_size(), 0); for (auto const & e : _costs) { if (v.contains(e._j)) { result[e._i] += e._v; } if (v.contains(e._i)) { result[e._j] += e._v; } } }
long __Call_isprime( CDSR_VMEval& /*vm*/, MMD_Address& addr, UniWord *arg ) { #if _DEBUG if( addr.param2 < 0 ) throw _T("__Call_(fun) : internal error, out of range"); #endif #ifndef _NO_HMATHBS CDSRNatural nV( (arg - 1)->getNatural() ); *(arg - 1) = CDSRInteger( ::IsNaturalSimple( nV ) ); #endif return 1 - addr.param3; }
Matrix3f Element::defGrad(Vector3f p, const std::vector<Vector3f> & X, const std::vector<Vector3f> & x) const { Matrix3f F=Matrix3f::identity(); for(int ii = 0; ii<nV(); ii++){ int vi = at(ii); Vector3f gradN = shapeFunGrad(ii,p,X); //outer product F += outerProd((x[vi] - X[vi]) , gradN); } //fem_error = FEM_OK; if(F.determinant()<0){ fem_error = FEM_ERROR_INVERT; } return F; }
//#include <cplex.h> // void CliquePartitionProblem::cps(std::string const &fileName, ILpSolver & solver) const { int const n(nV()); // char const binary(solver.binary()); char const continuous(solver.continuous()); char const leq(solver.leq()); char const eq(solver.eq()); char const geq(solver.geq()); // ColumnBuffer columnBuffer(continuous); DoubleVector denseCost(n * (n - 1), 0); for (auto const & e : _costs) { int const u(e._i); int const v(e._j); int const id(ijtok(n, u, v)); denseCost[id] = e._v; } //cpCost(denseCost); //IntVector index(n * (n - 1)); int nCols(0); for (int u(0); u < nV(); ++u) { for (int v(u + 1); v < nV(); ++v, ++nCols) { int const id(ijtok(n, u, v)); columnBuffer.add(denseCost[id], binary, 0, 1, GetStr("x_", u, "_", v)); if (id != nCols) { std::cout << "wrong numbering" << std::endl; std::exit(-1); } } } columnBuffer.add(cst(), continuous, 1, 1, "CST"); solver.add(columnBuffer); RowBuffer rowBuffer; double const eps(1e-20); for (int u(0); u < nV(); ++u) { for (int v(u + 1); v < nV(); ++v) { int const uv(ijtok(n, u, v)); for (int w(v + 1); w < nV(); ++w) { int const uw(ijtok(n, u, w)); int const vw(ijtok(n, v, w)); if (denseCost[uv] > -eps || denseCost[vw] > -eps) { rowBuffer.add(1, leq, GetStr("T_", u, "_", v, "_", w)); rowBuffer.add(uv, 1); rowBuffer.add(vw, 1); rowBuffer.add(uw, -1); } if (denseCost[vw] > -eps || denseCost[uw] > -eps) { rowBuffer.add(1, leq, GetStr("T_", v, "_", w, "_", u)); rowBuffer.add(vw, 1); rowBuffer.add(uw, 1); rowBuffer.add(uv, -1); } if (denseCost[uw] > -eps || denseCost[uv] > -eps) { rowBuffer.add(1, leq, GetStr("T_", w, "_", u, "_", v)); rowBuffer.add(uw, 1); rowBuffer.add(uv, 1); rowBuffer.add(vw, -1); } } } } solver.add(rowBuffer); solver.maximize(); solver.write(fileName + ".lp"); solver.run(); double objval = solver.objValue(); std::cout << "optimal solution value : " << std::setprecision(20) << objval << std::endl; }
Cube::Cube() : TriMesh() { _name = "Cube"; // vertex coordinates static const GLfloat v[8][3] = { {-1,-1,-1},{-1,1,-1},{1,1,-1},{1,-1,-1}, {-1,-1, 1},{-1,1, 1},{1,1, 1},{1,-1, 1} }; // triangles vertex indices static const GLint t[12][3] = { {1,2,0},{3,0,2}, // bottom triangles {1,5,6},{2,1,6},{2,6,3},{3,6,7},{3,7,0},{0,7,4},{0,4,1},{1,4,5}, // side triangles {4,7,5},{7,6,5} // top triangles }; // triangle normals static const GLint nt[12][3] = { {0,0,-1},{0,0,-1}, // bottom triangle normals {0,1,0},{0,1,0},{1,0,0},{1,0,0},{0,-1,0},{0,-1,0},{-1,0,0},{-1,0,0}, // side triangle normals {0,0,1},{0,0,1} // top triangle normals }; // triangle vertex normals static const GLint nv[36][3] = { {0,0,-1},{0,0,-1},{0,0,-1},{0,0,-1},{0,0,-1},{0,0,-1}, // bottom triangle vertex normals {0,1,0},{0,1,0},{0,1,0},{0,1,0},{0,1,0},{0,1,0}, // side triangle vertex normals {1,0,0},{1,0,0},{1,0,0},{1,0,0},{1,0,0},{1,0,0}, {0,-1,0},{0,-1,0},{0,-1,0},{0,-1,0},{0,-1,0},{0,-1,0}, {-1,0,0},{-1,0,0},{-1,0,0},{-1,0,0},{-1,0,0},{-1,0,0}, {0,0,1},{0,0,1},{0,0,1},{0,0,1},{0,0,1},{0,0,1} // top triangle vertex normals }; //--- Fill vertices and triangles vectors // Fill vertices vector for (int i=0; i<8 ; ++i) this->addVertex(v[i][0], v[i][1], v[i][2]); // Fill triangles vector for (int i=0; i<12; ++i) this->addTriangle(t[i][0], t[i][1], t[i][2]); // Fill normals vectors bool use_computed_normals = true; if (use_computed_normals) { computeNormalsT(); // to be fixed computeNormalsV(); // to be fixed } else { // use manually defined normals // set triangle normals for (int i=0; i<12; ++i) { Normal nT(nt[i][0], nt[i][1], nt[i][2]); this->addNormalT(nT); } // set triangle vertex normals for (int i=0; i<36; ++i) { Normal nV(nv[i][0], nv[i][1], nv[i][2]); this->addNormalV(nV); } } }