/** * Constructs a TSP with the input weight matrix and the selected encoding * @param[in] weights an std::vector of std::vector representing a square matrix. * @param[in] encoding a pagmo::problem::tsp::encoding representing the chosen encoding * @param[in] capacity maximum vehicle capacity */ tsp_vrplc::tsp_vrplc(const std::vector<std::vector<double> >& weights, const base_tsp::encoding_type& encoding, const double& capacity): base_tsp(weights.size(), compute_dimensions(weights.size(), encoding)[0], compute_dimensions(weights.size(), encoding)[1], encoding ), m_weights(weights), m_capacity(capacity) { if (m_capacity <= 0) { pagmo_throw(value_error, "Maximum vehicle capacity needs to be strictly positive"); } check_weights(m_weights); }
//############################################################################# // "unitize" a model by translating it to the origin and // scaling it to fit in a unit cube around the origin. // Returns the scale factor used. //############################################################################# GLfloat Model::unitize() { GLuint i; // max/mins of the model GLfloat maxx, minx, maxy, miny, maxz, minz; // model width, height, and depth GLfloat w, h, d; // center of the model GLfloat cx, cy, cz; // unitizing scale factor GLfloat scale; // default values w = h = d = 2.0; // calculates the dimensions the model compute_dimensions(maxx, minx, maxy, miny, maxz, minz, w, h, d); // calculate center of the model cx = (maxx + minx) / 2.0; cy = (maxy + miny) / 2.0; cz = (maxz + minz) / 2.0; // calculate unitizing scale factor scale = 2.0 / maximum_value( maximum_value(w, h), d ); // translate around center then scale for (i = 1; i <= m_numvertices; i++) { m_vertices[3 * i + 0] -= cx; m_vertices[3 * i + 1] -= cy; m_vertices[3 * i + 2] -= cz; m_vertices[3 * i + 0] *= scale; m_vertices[3 * i + 1] *= scale; m_vertices[3 * i + 2] *= scale; } // returns the scale factor used return scale; }
//############################################################################# // Generates texture coordinates according to a // linear projection of the texture map. It generates these by // linearly mapping the vertices onto a square. //############################################################################# GLvoid Model::linear_texture() { Group *group; GLfloat dimensions[3]; GLfloat x, y, scalefactor; GLuint i; if (m_texcoords) delete [] m_texcoords; m_numtexcoords = m_numvertices; m_texcoords= new GLfloat [2*(m_numtexcoords+1)]; GLfloat a, b, c, d, e, f; compute_dimensions(a, b, c, d, e, f, dimensions[0], dimensions[1], dimensions[2]); scalefactor = 2.0 / absolute_value(maximum_value(maximum_value(dimensions[0], dimensions[1]), dimensions[2])); // do the calculations for(i = 1; i <= m_numvertices; i++) { x = m_vertices[3 * i + 0] * scalefactor; y = m_vertices[3 * i + 2] * scalefactor; m_texcoords[2 * i + 0] = (x + 1.0) / 2.0; m_texcoords[2 * i + 1] = (y + 1.0) / 2.0; } // go through and put texture coordinate indices in all the triangles group = m_groups; while(group) { for(i = 0; i < group->numtriangles; i++) { m_triangles[group->triangles[i]].set_tindex(0,m_triangles[group->triangles[i]].inq_vindex(0)); m_triangles[group->triangles[i]].set_tindex(1,m_triangles[group->triangles[i]].inq_vindex(1)); m_triangles[group->triangles[i]].set_tindex(2,m_triangles[group->triangles[i]].inq_vindex(2)); } group = group->next; } }