Search Results

Search found 614 results on 25 pages for 'vectors'.

Page 13/25 | < Previous Page | 9 10 11 12 13 14 15 16 17 18 19 20  | Next Page >

  • Dijkstras Algorithm exaplination java

    - by alchemey89
    Hi, I have found an implementation for dijkstras algorithm on the internet and was wondering if someone could help me understand how the code works. Many thanks private int nr_points=0; private int[][]Cost; private int []mask; private void dijkstraTSP() { if(nr_points==0)return; //algorithm=new String("Dijkstra"); nod1=new Vector(); nod2=new Vector(); weight=new Vector(); mask=new int[nr_points]; //initialise mask with zeros (mask[x]=1 means the vertex is marked as used) for(int i=0;i<nr_points;i++)mask[i]=0; //Dijkstra: int []dd=new int[nr_points]; int []pre=new int[nr_points]; int []path=new int[nr_points+1]; int init_vert=0,pos_in_path=0,new_vert=0; //initialise the vectors for(int i=0;i<nr_points;i++) { dd[i]=Cost[init_vert][i]; pre[i]=init_vert; path[i]=-1; } pre[init_vert]=0; path[0]=init_vert; pos_in_path++; mask[init_vert]=1; for(int k=0;k<nr_points-1;k++) { //find min. cost in dd for(int j=0;j<nr_points;j++) if(dd[j]!=0 && mask[j]==0){new_vert=j; break;} for(int j=0;j<nr_points;j++) if(dd[j]<dd[new_vert] && mask[j]==0 && dd[j]!=0)new_vert=j; mask[new_vert]=1; path[pos_in_path]=new_vert; pos_in_path++; for(int j=0;j<nr_points;j++) { if(mask[j]==0) { if(dd[j]>dd[new_vert]+Cost[new_vert][j]) { dd[j]=dd[new_vert]+Cost[new_vert][j]; } } } } //Close the cycle path[nr_points]=init_vert; //Save the solution in 3 vectors (for graphical purposes) for(int i=0;i<nr_points;i++) { nod1.addElement(path[i]); nod2.addElement(path[i+1]); weight.addElement(Cost[path[i]][path[i+1]]); } }

    Read the article

  • Dijkstra's Algorithm explanation java

    - by alchemey89
    Hi, I have found an implementation for dijkstras algorithm on the internet and was wondering if someone could help me understand how the code works. Many thanks private int nr_points=0; private int[][]Cost; private int []mask; private void dijkstraTSP() { if(nr_points==0)return; //algorithm=new String("Dijkstra"); nod1=new Vector(); nod2=new Vector(); weight=new Vector(); mask=new int[nr_points]; //initialise mask with zeros (mask[x]=1 means the vertex is marked as used) for(int i=0;i<nr_points;i++)mask[i]=0; //Dijkstra: int []dd=new int[nr_points]; int []pre=new int[nr_points]; int []path=new int[nr_points+1]; int init_vert=0,pos_in_path=0,new_vert=0; //initialise the vectors for(int i=0;i<nr_points;i++) { dd[i]=Cost[init_vert][i]; pre[i]=init_vert; path[i]=-1; } pre[init_vert]=0; path[0]=init_vert; pos_in_path++; mask[init_vert]=1; for(int k=0;k<nr_points-1;k++) { //find min. cost in dd for(int j=0;j<nr_points;j++) if(dd[j]!=0 && mask[j]==0){new_vert=j; break;} for(int j=0;j<nr_points;j++) if(dd[j]<dd[new_vert] && mask[j]==0 && dd[j]!=0)new_vert=j; mask[new_vert]=1; path[pos_in_path]=new_vert; pos_in_path++; for(int j=0;j<nr_points;j++) { if(mask[j]==0) { if(dd[j]>dd[new_vert]+Cost[new_vert][j]) { dd[j]=dd[new_vert]+Cost[new_vert][j]; } } } } //Close the cycle path[nr_points]=init_vert; //Save the solution in 3 vectors (for graphical purposes) for(int i=0;i<nr_points;i++) { nod1.addElement(path[i]); nod2.addElement(path[i+1]); weight.addElement(Cost[path[i]][path[i+1]]); } }

    Read the article

  • Loading and saving a class to a binary file

    - by user146780
    I don't know if this is possible but, I have a class and I'v made an instance of it. I also put things in it. It has vectors and other things. I was wondering if I could save its contents (the instance) to a binary file, then reload it and cast it in from the file. Thanks

    Read the article

  • machine learning and code generator from strings

    - by BCS
    The problem: Given a set of hand categorized strings (or a set of ordered vectors of strings) generate a decision function to categorize more input. The question: are there any tools out there that will do that? I'm thinking of some kind of reasonably polished, download, install and go kind of things, as opposed to to some library or a brittle academic program.

    Read the article

  • How do games move around objects (in general)

    - by user146780
    I'm sure there's not just 1 answer to this but, do game engines actually change the vectors in memory, or use gltransformations? Because pushing and popping the matrix all the time seems inefficient, but if you keep modifying the verticies you cant make use of display lists. So I'm wondering how it's done in general. Thanks

    Read the article

  • R: preventing unlist to drop NULL values

    - by nico
    I'm running into a strange problem. I have a vector of lists and I use unlist on them. Some of the elements in the vectors are NULL and unlist seems to be dropping them. How can I prevent this? Here's a simple (non) working example showing this unwanted feature of unlist a = c(list("p1"=2, "p2"=5), list("p1"=3, "p2"=4), list("p1"=NULL, "p2"=NULL), list("p1"=4, "p2"=5)) unlist(a) p1 p2 p1 p2 p1 p2 2 5 3 4 4 5

    Read the article

  • Working with a figure file in Matlab

    - by 49er
    I've got a .fig file showing the intensities of 2d data. How do I obtain the values when I load it in Matlab? Is it even possible? When I try playing with the children properties I am able to obtain only the size of my x and y vectors, not the values themselves which I don't know how to extract.

    Read the article

  • Class destructor memory handling in C++

    - by wyatt
    What potential memory leaks won't an implicit destructor handle? I know that if you have anything stored on the heap it won't handle it, and if you have a connection to a file or a database, that needs to be handled manually. Is there anything else? What about, say, non-base data types like vectors? Also, in an explicit destructor, need you destroy non-heap variables which would have been destroyed by the implicit, or are they handled automatically? Thanks

    Read the article

  • Code to extrude 2d geometry to 3d

    - by Bgnt44
    Hi, is there any simple way to extrude a 2d geomtry (vectors ) to a 3d shape assuming extruding parameter are lenght (double) and angle (degree) so it should render like a cone ( all z lines going to one point )

    Read the article

  • Does acos, atan functions in stl uses lots of cpu cycles

    - by jan
    Hi all, I wanted to calculate the angle between two vectors but I have seen these inverse trig operations such as acos and atan uses lots of cpu cycles. Is there a way where I can get this calculation done without using these functions? Also, does these really hit you when you in your optimization?

    Read the article

  • C++ Vector vs Array (Time)

    - by vsha041
    I have got here two programs with me, both are doing exactly the same task. They are just setting an boolean array / vector to the value true. The program using vector takes 27 seconds to run whereas the program involving array with 5 times greater size takes less than 1 s. I would like to know the exact reason as to why there is such a major difference ? Are vectors really that inefficient ? Program using vectors #include <iostream> #include <vector> #include <ctime> using namespace std; int main(){ const int size = 2000; time_t start, end; time(&start); vector<bool> v(size); for(int i = 0; i < size; i++){ for(int j = 0; j < size; j++){ v[i] = true; } } time(&end); cout<<difftime(end, start)<<" seconds."<<endl; } Runtime - 27 seconds Program using Array #include <iostream> #include <ctime> using namespace std; int main(){ const int size = 10000; // 5 times more size time_t start, end; time(&start); bool v[size]; for(int i = 0; i < size; i++){ for(int j = 0; j < size; j++){ v[i] = true; } } time(&end); cout<<difftime(end, start)<<" seconds."<<endl; } Runtime - < 1 seconds Platform - Visual Studio 2008 OS - Windows Vista 32 bit SP 1 Processor Intel(R) Pentium(R) Dual CPU T2370 @ 1.73GHz Memory (RAM) 1.00 GB Thanks Amare

    Read the article

  • Create a dataset: extract features from text documents (TF-IDF)

    - by BigG
    I've to create a dataset from some text files, writing them as vectors of features. Something like this: doc1: 1,0.45 6,0.001 94,0.1 ... doc2: 3,0.5 98,0.2 ... ... each position of the vector represent a word, and the score is given by something like TF-IDF. Do you know some library/tool/whatever for this? (java is better)

    Read the article

  • Move an object in the direction of a bezier curve?

    - by Sent1nel
    I have an object with which I would like to make follow a bezier curve and am a little lost right now as to how to make it do that based on time rather than the points that make up the curve. .::Current System::. Each object in my scene graph is made from position, rotation and scale vectors. These vectors are used to form their corresponding matrices: scale, rotation and translation. Which are then multiplied in that order to form the local transform matrix. A world transform (Usually the identity matrix) is then multiplied against the local matrix transform. class CObject { public: // Local transform functions Matrix4f GetLocalTransform() const; void SetPosition(const Vector3f& pos); void SetRotation(const Vector3f& rot); void SetScale(const Vector3f& scale); // Local transform Matrix4f m_local; Vector3f m_localPostion; Vector3f m_localRotation; // rotation in degrees (xrot, yrot, zrot) Vector3f m_localScale; } Matrix4f CObject::GetLocalTransform() { Matrix4f out(Matrix4f::IDENTITY); Matrix4f scale(), rotation(), translation(); scale.SetScale(m_localScale); rotation.SetRotationDegrees(m_localRotation); translation.SetTranslation(m_localTranslation); out = scale * rotation * translation; } The big question I have are 1) How do I orientate my object to face the tangent of the Bezier curve? 2) How do I move that object along the curve without just setting objects position to that of a point on the bezier cuve? Heres an overview of the function thus far void CNodeControllerPieceWise::AnimateNode(CObject* pSpatial, double deltaTime) { // Get object latest pos. Vector3f posDelta = pSpatial->GetWorldTransform().GetTranslation(); // Get postion on curve Vector3f pos = curve.GetPosition(m_t); // Get tangent of curve Vector3f tangent = curve.GetFirstDerivative(m_t); } Edit: sorry its not very clear. I've been working on this for ages and its making my brain turn to mush. I want the object to be attached to the curve and face the direction of the curve. As for movement, I want to object to follow the curve based on the time this way it creates smooth movement throughout the curve.

    Read the article

  • does passing __m128i objects by reference to inline function cause these objects to be moved to stac

    - by ~buratinas
    Hello, I'm writing transpose function for 8x16bit vectors with SSE2 intrinsics. Since there are 8 arguments for that function (a matrix of 8x8x16bit size), I can't do anything but pass them by reference. Will that be optimized by the compiler (I mean, will these __m128i objects be passed in registers instead of stack)? Code snippet: inline void transpose (__m128i &a0, __m128i &a1, __m128i &a2, __m128i &a3, __m128i &a4, __m128i &a5, __m128i &a6, __m128i &a7) { .... }

    Read the article

  • How do games move around objects (in general) (OGL)

    - by user146780
    I'm sure there's not just 1 answer to this but, do game engines actually change the vectors in memory, or use gltransformations? Because pushing and popping the matrix all the time seems inefficient, but if you keep modifying the verticies you cant make use of display lists. So I'm wondering how it's done in general. Thanks

    Read the article

  • C++ int vector to c#

    - by Stefan Koenen
    I'm doing a C# project and I want to call next_permutation from the algorithm library in C++. I found the way to call c++ functions in c# but i dont know how to get vectors from c++ and use it in c# (cause next_permutation require a int vector...) this is what I'm trying at the moment: extern void NextPermutation(vector<int>& permutation) { next_permutation (permutation.begin(),permutation.end()); } [DllImport("PEDLL.dll", CallingConvention = CallingConvention.Cdecl)] private static extern void NextPermutation(IntPtr test);

    Read the article

  • What happens if I give more inputs in estimateRigidTransform or getAffineTransform?

    - by user3531608
    I am using estimateRigidTransform with about two vectors of 100 points and is working FINE. But somehow getAffineTransform doesn't work. I know that findHomography finds the best matrix using RANSAC and getPerspectiveTransform needs only 4 points. My question is what happens if I give more inputs in estimateRigidTransform or getAffineTransform? Does it take only 4 points from input matrix? Or do some kind of RANSAC?

    Read the article

< Previous Page | 9 10 11 12 13 14 15 16 17 18 19 20  | Next Page >