mike_2000_17 2,669 21st Century Viking Team Colleague Featured Poster

But if the body receives consciousness in the same way that a cable box receives satellite signals

A cable box receives satellite signals?!? Ok... Well, I guess he meant the way a high-gain antenna receives VHF/UHF signals. I must assume that he is very poorly informed about the way radio telecommunications work. On the one end, there is a satellite with a high-power, high-gain, directional antenna that broadcasts powerful VHF/UHF signals from geosynchronous orbit (36,000 km altitude) directed at a region of Earth that requires about a few arc-seconds of pointing accuracy from its perspective. Then, the very faint remnant of the signals that actually makes it to the Earth and passed the atmospheric interference, is picked up by a high-gain antenna (the dish on your roof) pointing directly at the satellite. The signal, which is full of noise, is fed to a demodulator which attempts to lock on to the phase and frequency of the carrier wave, filter the noise around the frequency-band of interest, demodulate the signal, filter and demodulate a couple more times, and finally, get a digitally-encoded signal with good enough quality to use it.

The point of that lengthy explanation was to expose a few important problems. First of all, to send or receive any signal (of any kind) over a long distance requires either a tremendous amount of power, or a very large piece of hardware (like a very huge antenna). The laws that govern this are conservation of energy and basic …

tamcan commented: Kudos - I believe its all about the frequencies +0
mike_2000_17 2,669 21st Century Viking Team Colleague Featured Poster

stdafx.h is a Microsoft header that is specific to a feature called "pre-compiled headers" that the Visual C++ compiler (among others) provides. This is not a standard header, and you should not expect it to exist on any other platform than on Windows + Visual C++. If you are very much used to working with Visual Studio, you will soon realize how (intentionally) non-standard that platform is when it comes to C++.

The preferred IDE for Mac is definitely Xcode. If you don't like it, you might try the Mac port of CodeBlocks, which is a popular IDE (on any OS). You might also try Qt Creator, especially if you want to do some cross-platform GUI programs. Or Eclipse is another very "noob-friendly" IDE (I would say, "noob-only", but that's just my opinion). Or, you can do like many people do, just use an enhanced text editor, like sublime.

mike_2000_17 2,669 21st Century Viking Team Colleague Featured Poster

It's odd that you say Kubuntu is faster than gnome. I always thought gnome was leaner that kde?

I know, it's weird, but it's my impression in general. I know that KDE is "heavier" (i.e., more RAM usage, a bit longer start-up time), and it's still a bit heavier than Gnome 3 (which is significantly heavier than previous versions of Gnome). However, for some reason, I find it to be just faster overall when you use it. At least, that's my impression (note that my experiences with Gnome are a bit limited, since I love KDE and use it almost exclusively). My guess is that because KDE relies on Qt (which is where the relative "heaviness" comes from), which is a much more comprehensive GUI library, things are more homogeneously implemented, and thus, faster. Gnome is a lot more of a patchwork of different components, which leads to overhead for gluing them together. At least, that's the best explanation I can find.

The graphics is an onboard amd raedon chipset according to the datasheet.

That graphics card will require a proprietary driver (which you should be able to find through "Additional Drivers..."). The driver for Radeon cards is the Catalyst driver. I guess this is the one to download (but try going through Additional Drivers.. first).

I think that the open-source graphics drivers for Radeon cards are pretty bad, but only because the drivers that AMD provides for Linux are very good, so there …

iamthwee commented: Perfect +14
mike_2000_17 2,669 21st Century Viking Team Colleague Featured Poster

Yeah, computer languages are the "universal" languages, like C++:

/** Ceci est une classe pour représenter l'état d'une particule.
 * \note Den här klass är bara för tvâ dimensioner.
 */
struct TeilchenStand {
  double position[2];
  double geschwindigkeit[2];
};
mike_2000_17 2,669 21st Century Viking Team Colleague Featured Poster

As triumphost says, the C++ does come with both a sleep_for and a sleep_until function. Of course, these functions cannot come with any kind of standard guarantees about timing or being a busy-wait or not, or anything like that, but it provide the comforting thought that someone better than you spent some time implementing the most optimal sleep function for whatever platform you are using, and that is generally good enough for me.

While C++ could have extended or replaced the C functions with a more complete DateTime class or classes, to date they haven't done so

Yes they have, a few years ago. It's in the chrono header. It doesn't exactly go as far as doing "date", it only does "time". For dates, you would have to either rely on the legacy C time library or rely on boost gregorian.

Schol-R-LEA commented: Ah, I wasn't familar with <chrono>. I'll have to read up on that. Thank you. +10
mike_2000_17 2,669 21st Century Viking Team Colleague Featured Poster

The contents of the array are indeterminate, which is the "official" reason for the undefined behavior.

There is obviously a gray zone between indeterminate values and undefined behavior. If it wasn't for trap representations (which I doubt still exist on any hardware at all), there would really be no reason why reading a variable of indeterminate value would cause undefined behavior. It might be the case that, very strictly-speaking, this is UB, but certainly not in practice.

And from what I have read on trap representations (which I just learned about in this thread), it seems that (1) in C++, trap representations only apply to floating-point numbers, and that (2) any IEEE-compliant processor must not have trap representations on floating-point numbers. And also, even C99 integer trap representations seem so rare that even the committee members looked for example architectures and could not find any. I think that the standards (C/C++) could be re-worded to say that it is well-defined behavior to read an indeterminate value (such as an uninitialized variable), and it would not change anything at all for any implementation or architectures that anyone still uses (it seems the last processor to have a trap representation on floating point numbers was an old DSP chip from the 80s).

Is there any other reason why reading a indeterminate value would be undefined behavior?

I don't mind indeterminate values at all if I access an array with no initial value. I just don't want my program …

mike_2000_17 2,669 21st Century Viking Team Colleague Featured Poster

Why is accessing data in an uninitialised array undefined behaviour?

It's not really clear whether this is undefined behavior or not. If you read uninitialized data, you will read a garbage value, i.e., whatever arbitrary combination of bits that happens to be in that memory location at the time of the allocation. That's what's going to happen in pretty much 99.9999..% of platforms (unless you compile in debug mode where "uninitialized" data is often initialized for easily spotting such errors).

Undefined behavior is a technical term pertaining to the C++ standard. What the standard says here is that if you dynamically allocate an array, the elements get "default-initialized", which is the standard term to mean "if class type, then default constructor is called; if trivial type (e.g., int), then left uninitialized". Then the standard mentions that uninitialized primitive values have "indeterminate value", which (to me, at least) implies that reading that value is well-defined behavior, it's just the value that is indeterminate. In that case, it's well-defined behavior, it's just that the behavior is to obtain a "garbage" value.

Anyhow, these are just SO-style language-lawyers' discussions.

Any ideas what I could do to keep the speed of uninitialising without breaking any rules?

The rule is that you cannot meaningfully (UB or not) read the value of an uninitialized variable (part of an array or not). But, obviously, you can write to it. You could pre-allocate an array before you come to the point of having values …

mike_2000_17 2,669 21st Century Viking Team Colleague Featured Poster
Introduction

The subject of this tutorial is a bit more advanced than the subjects I have tackled in the past, but I hope this will find some interested readers. From time to time in C++, programmers find themselves torn apart between using a Generic Programming style which primarily involves the use of templates and compile-time mechanisms (e.g., STL), and using a Object-Oriented Programming style that often favors inheritance and run-time dispatching mechanisms (e.g., Qt). As it is so often the case, there is no obvious "winner", i.e., there is no paradigm that should always be preferred, even within a single problem domain.

This tutorial will take you through a number of alternative techniques and will describe how these choices affect the performance and flexibility of the code. The novice-to-advanced programmers will discover in this tutorial a number of somewhat classic techniques that will certainly come in handy. The expert programmers might rediscover those techniques but mostly will see in this tutorial an occasion to reflect on some of the trade-offs that they face and the surgical ways to manipulate them.

Working Example: Printing the Fibonacci Sequence

For this tutorial, we'll be using a very simple example problem: printing a Fibonacci sequence. As is usual in these kinds of examples, the techniques that I will show will be much too complex for the simple example used (i.e., overkill), but the point is to imagine a more complicated scenario where the techniques shown are more appropriate given the complexity of the problem. …

LaxLoafer commented: Impressive. +4
mike_2000_17 2,669 21st Century Viking Team Colleague Featured Poster

1.What is the "Global Rebuilding" technique exactly?

I would assume that it refers to a complete destruction of the tree and a complete reconstruction of it. This is what I usually call a "collect-and-rebuild" process. When you have a tree or a sub-tree that needs to be re-balanced, some traditional approaches (e.g., in red-black trees or AVL-trees) involve doing some tinkering with the structure, such as tree rotations to re-shape the tree by swapping or splitting some parent-child relationships. However, in some cases, this is too hard or not practical at all (e.g., in contiguous storage, like a cache-oblivious implementation). So, instead of trying to repair an unbalanced tree or subtree, it is easier to just collect all the node values that you want to keep (e.g., removing those you want to delete, or adding those you want to insert), destroy the tree, and re-build it back from the array of node values that you collected. In many kinds of search trees, this is the only option when you need to re-balance a tree or subtree.

It may sound like a horrible solution, because it seems really expensive to continuously destroy and rebuild the tree whenever you add or remove elements from it, but in reality, this is amortized by the fact that it is very rare that a tree becomes unbalanced enough to requires a complete reconstruction. Typically, the majority of insertions and deletions don't cause any significant imbalance in the affected subtree. But when it does, …

rubberman commented: Good explanation Mike. +12
mike_2000_17 2,669 21st Century Viking Team Colleague Featured Poster

A bitmask is a special number that has a bunch of bits (0/1) set to 1 such that when you do a bitwise AND with another number, you get only those bit values. This is useful in many contexts, it basically extracts only the parts of a number that are of interest for a particular task.

One example where a bitmask is used is for subnet masks on IPv4 addresses. An IPv4 address is a 32bit integer value that represents the address of a device on the internet (computer, router, server, etc..). It is usually written in the form 192.168.0.1 where each number is one byte (8 bits) which is a number between 0 and 255. So, the four numbers together make up the 4 bytes (32bits) address. A typical "local network" subnet mask is 255.255.255.0 which is a number which has all leading 24bits set to 1. If you do a bitwise AND between the mask (255.255.255.0) and the address 192.168.0.1, you get 192.168.0.0. And if you do it with the address 192.168.0.23, you also get 192.168.0.0. You see how this can be useful to determine if the address is part of the particular local network or not.

Another example of where bitmasks are useful is when you use different bits of a single number to mean different things, which are usually called "flags". It's a basic mechanism to store a bunch of simple options within a single number (if you have enough bits to accommodate it). Here is …

mike_2000_17 2,669 21st Century Viking Team Colleague Featured Poster

Really funny. Any time I see people arguing about language X vs. Y, I'll link to that article. But, if you see me arguing about language X vs. Y, then, obviously, I'm right! ;)

<M/> commented: XD +10
mike_2000_17 2,669 21st Century Viking Team Colleague Featured Poster

I can't see how that could go wrong, given the pissy tendencies of many SO regulars. :rolleyes:

Yeah. Their fuses are about as short as their answers. Their ability to accept criticism is inversely proportional to their reputation points. Their concern about helping others can only reside in the very narrow space between questions that are: too redundant with others; too specific; too long to answer; too subjective; and, not answerable with a copy-pasted answer riddled with links to other SO threads. A convenient philosophy for any lazy educator (how often do teachers do the same? And how much do you like those teachers... :rolleyes: ).

mike_2000_17 2,669 21st Century Viking Team Colleague Featured Poster

It's basically user preference. Vi is meant to be a very comprehensive editor, and it has tons of commands and special features. Nano is more of a basic text editor (think "notepad in the terminal", i.e., nothing more than copy-paste, exit-save). I generally prefer nano because for the times that I need a terminal-based text editor, I usually don't need a very complicated editor, and I don't like having to remember all the commands when all I ever need to do is write some text and then "save-and-exit" (and nano has a command-reminder at the bottom). I guess if you are used to vi (and know the commands) it is "better" than nano in the sense that it has more features, but to me, it's needlessly feature-rich for most things I do in a terminal-based text-editor.

mike_2000_17 2,669 21st Century Viking Team Colleague Featured Poster

What part of his stereotype do you think is false?

He sort of has this "dorky accountant" look, which is what most people think IT people or programmers look like. But I have never met any of these mythical "dorky accountant" programmers. I think programming and IT is a very creative endeavour, and that creative personality is usually reflected, one way or another, in people's looks. Finding an average and "conformist" picture for some representative daniweb mascot is a pointless endeavour.

mike_2000_17 2,669 21st Century Viking Team Colleague Featured Poster

@AD: I don't think that the OP is really interested in a Qt vs. .NET debate in this thread. It would be like answering a question about a problem with some C++ code, and recommend as an answer to opt for a completely different language instead. It's off-topic. In any case, any .NET code is definitely never completely compiled to "native" code, this is by design of the whole .NET framework. When writing programs or libraries for the .NET framework (through C# or C++/CLI, or whatever), the "compiler" will compile that code to CIL, which is a high-level pseudo-assembly code that acts as an intermediate language. A .NET "executable" is actually just a launcher that launches the .NET framework (if not already running) and launches the execution of the CIL code embedded in that "executable". When CIL code is "executed", it is, in fact, interpreted on the fly (also called Just-In-Time compilation). There is a world of difference between CIL and actual native code (like you would find in an object file (.o/.obj) from some C/C++ compilation, you could say "conceptually similar" but certainly not similar in practice). And yes, to answer the OP's concerns, .NET programs will be bloated and slow, non-portable and heavy-weight (heavy distributables), due to the reliance on the .NET framework and JIT compilation.

before I do something irreversible to my IED environment (vs 2010)

Installing the Qt add-on for Visual Studio is neither irreversible nor is it gonna interfere with anything else, in …

mike_2000_17 2,669 21st Century Viking Team Colleague Featured Poster

There are a number of ways to do it. Here are some options:

1) Use the C++ counterpart to "SortedList" which is called std::set (see docs). This is a container of elements that are sorted. However, just like SortedList, this is implemented using a binary search tree (some kind of red-black tree) that uses "links" between nodes. For storing elements of 16 bytes each (probably a POD-type), and when you only have a few thousand of them, this solution will be very far from optimal in terms of performance. Probably about as good as the C# version, which is terrible by C++ standards.

2) Keep a sorted array (vector) and insert elements into it. Something like this:

void addElementToVector(std::vector<T>& v, T elem, std::size_t max_size) {
  if( ( max_size <= v.size() ) && ( elem >= v.back() ) )
    return; // nothing to do.

  if( max_size > v.size() ) { // if empty room in v
    // add room at the end:
    v.push_back(elem);
  };
  // find the position for the element
  auto pos = std::upper_bound(v.begin(), v.end()-1, elem);
  // and move the array around it:
  std::move_backward(pos, v.end()-1, pos+1);
  // and set the new element:
  *pos = elem;
};

You can look at the docs for upper_bound and move_backward to figure out how this works. It's a simple matter of finding the proper place to put the new element within the existing array, and then move the sub-array by one position such that the new …

mike_2000_17 2,669 21st Century Viking Team Colleague Featured Poster

Are you finding yourself using the new homepage now?

Yes. And I'm glad Fred is gone!

<M/> commented: ikr +0
mike_2000_17 2,669 21st Century Viking Team Colleague Featured Poster

yo mama is so fat that when she went for a studio photo shoot, they had to use a panoramic lens.

<M/> commented: lol +0
mike_2000_17 2,669 21st Century Viking Team Colleague Featured Poster

Here are some "safer" alternatives:

1) use the namespace only within a function body:

#include <iostream>

int main()
{
    using namespace std;
    cout << "Blah, blah, blah";
    return 0;
}

This limits the scope of the namespace usage, reducing the scope at which names could clash.

2) use the individual items instead of the whole namespace:

#include <iostream>

using std::cout; // at global scope

int main()
{
    using std::endl; // or at function scope

    cout << "Blah, blah, blah" << endl;

    return 0;
}

Again, this limits the name-clashes while reducing the verbosity when you only need a few elements of the namespace.

3) create a namespace alias:

#include <boost/program_options.hpp>

namespace po = boost::program_options;

int main(int argc, char** argv) {
  // use elements of the program_options namespace
  //  with po:: instead of boost::program_options::

  // ...

  return 0;
};

I had to show this with Boost.Program-Options, just as an example of a case when there can be a fairly long namespace name. Creating such an alias is a simple trick to reduce the verbosity.

mike_2000_17 2,669 21st Century Viking Team Colleague Featured Poster

Yo mama is so stupid that when she went to donate plasma, she brought her television set.

cproger commented: lol +0
mike_2000_17 2,669 21st Century Viking Team Colleague Featured Poster

@<M/> I guess you never heard of the notion of feet in prosody, nor about rhymes. Rev Jim's version is a beauty in both of these aspects. I'm just saying you shouldn't change your career path to become a song-writer just yet.

<M/> commented: ha... +0
cproger commented: :) +0
mike_2000_17 2,669 21st Century Viking Team Colleague Featured Poster

Just read the docs. It's simply:

DecimalFormat myFormatter = new DecimalFormat("#,##0.0#");
<M/> commented: Thanks :D +0
mike_2000_17 2,669 21st Century Viking Team Colleague Featured Poster

I guess you have to add this line at the top:

import java.text.DecimalFormat;
<M/> commented: ... i now feel dumb. :D +9
mike_2000_17 2,669 21st Century Viking Team Colleague Featured Poster

You should notice this line:

Line 3 Right: The total is 10123607318 

That is one big number. In fact, it is larger than what you can represent with a 32bit integer type, which is what int is in Java (the number is about 10 billion, and the max for an int is about 2 billion). This is an integer overflow problem. You need to sum-up the total into a larger integer than that, like long.

The second problem is about formatting only:

Line 4 Wrong: Average is -124975.0
Line 4 Right: Average is -124,975.00 

You have your output set to putting a comma between thousands. You need to change that setting. I think you can just do:

 DecimalFormat myFormatter = new DecimalFormat("#.0#");
System.out.println("Average is " + myFormatter.format(total * 1.0D / count));
<M/> commented: Thank you! +0
mike_2000_17 2,669 21st Century Viking Team Colleague Featured Poster

what he is really doing and how can i protect my account ? and what methods he's using ?

You should ask him. But I have a feeling he is imaginary... and that you're just fishing for some tips on how to hack people's accounts.

ddanbe commented: Absolutely! +14
mike_2000_17 2,669 21st Century Viking Team Colleague Featured Poster

I hope you guys realize you might be putting yourself in danger of being accused of plagarism. Just saying.

BTW, to solve the minimum-spanning-tree (which is actually just the same as the Dijkstra algorithm) you can do:

boost::prim_minimum_spanning_tree(
   g, goal_v, 
   get(&VertexProperty::predecessor, g),
   get(&VertexProperty::distance, g),
   get(&EdgeProperty::weight, g),
   boost::identity_property_map(),
   do_nothing_dijkstra_visitor());

which also sets the predecessors to make up the minimum-spanning-tree.

As for the traveling salesman problem, you can create a vector to hold the tour, and call the BGL function for an approximate TSP solution, as follows:

std::vector<Vertex> tsp_tour;

boost::metric_tsp_approx_tour_from_vertex(
  g, start_v,
  get(&EdgeProperty::weight, g), 
  back_inserter(tsp_tour));

And then, the vector tsp_tour will contain the list of vertices visited by a TSP tour.

mike_2000_17 2,669 21st Century Viking Team Colleague Featured Poster

No, you need to do this:

while (std::getline(fin,tempString)){ // (Location1, Location2, 6)
        //remove parentheses
        tempString.erase( tempString.begin(), tempString.begin() + tempString.find('(') + 1 );
        tempString.erase( tempString.begin() + tempString.find(')'), tempString.end() );

        std::cout<<std::endl<<tempString;

        std::stringstream temp_ss(tempString);
        std::getline(temp_ss, tempName1, ',');
        { 
          std::size_t first_c = tempName1.find_first_not_of(' ');
          std::size_t last_c = tempName1.find_last_not_of(' ');
          tempName1 = tempName1.substr(first_c, last_c - first_c + 1);
        };

        std::getline(temp_ss, tempName2, ',');
        { 
          std::size_t first_c = tempName2.find_first_not_of(' ');
          std::size_t last_c = tempName2.find_last_not_of(' ');
          tempName2 = tempName2.substr(first_c, last_c - first_c + 1);
        };

        temp_ss >> weight;
        // Add edge to graph, by finding vertices associated 
        //  to tempName1 and tempName2:
        add_edge(name2v[tempName1],name2v[tempName2],EdgeProperty(weight), g);
    }
mike_2000_17 2,669 21st Century Viking Team Colleague Featured Poster

only another hour, I gotta say I didn't think this project would be that hard when he gave us the write up (in theory this should have only taken an hour), but the sytax is so daunting I'm not sure how we were expected to have time to do all three tiers of this project.

I think your prof assumed that the students are familiar with C++ already. A person who is already familiar with C++ syntax and has an average level of competence with the language can solve this assignment within a couple of hours, easily. I don't know if it was stated anywhere in the course pre-requisites that good C++ knowledge was necessary for the course, but if it was, then this is certainly a reasonable assignment. It is not reasonable if there was no pre-requisite of the sort. If you ignored that pre-requisite, thinking that you could just learn C++ as you go, then you are currently experiencing the consequences of that poor judgement call.

mike_2000_17 2,669 21st Century Viking Team Colleague Featured Poster

The find function finds the index of the first character specified. Just read the docs for string. If there are no characters equal to that one, it will return the index at the end of the string.

Actually, the easiest way to just remove all the spaces is this:

tempName1.erase(std::remove(tempName1.begin(), tempName1.end(), ' '), tempName1.end());

But that will also remove spaces in the middle of the name.

To extract only the string in the middle (between leading and trailing spaces), you can use this:

std::size_t first_c = tempName1.find_first_not_of(' ');
std::size_t last_c = tempName1.find_last_not_of(' ');
tempName1 = tempName1.substr(first_c, last_c - first_c + 1);

which looks for the first non-space character and the last non-space character, and then extract the sub-string between those two indices (the + 1 is to get the length between the indices to include the last non-space character).

mike_2000_17 2,669 21st Century Viking Team Colleague Featured Poster

Yes that's right.

mike_2000_17 2,669 21st Century Viking Team Colleague Featured Poster

yeah mike is awesome, he is the only reason I've not failed this class already.

I sympathize with you guys. I think your prof really threw you in the deep end with this assignment. If you were to do this without BGL, you would have to implement an adjacency-list data structure and a Dijkstra algorithm, both of which can be a big challenge for any programmer, let alone beginners. If you use the BGL, you don't have to implement all that, but you have to use a library that is definitely not meant for beginners to use (i.e., although, as an expert, I love the BGL for its flexibility, it is often criticised for being too difficult to use). It is a bit unreasonable for a prof to expect you to pick-up on being able to use the BGL just like that, he should have given you at least a whole lecture (e.g., 3 hours) on how the BGL works and how to use it.

This is why I'm helping you far more than I usually would.

mike_2000_17 2,669 21st Century Viking Team Colleague Featured Poster

The program that I have posted last works correctly on my end. I tried using the following file:

Vertices:
Location1,Location2,Location3,Location4,Location5
Edges:
(Location1,Location2,5)
(Location2,Location3,1)
(Location2,Location4,2)
(Location3,Location5,3)
(Location1,Location4,1)

And I ran the program (exactly as posted a few posts back), and I got the following output:

$ ./dijkstra_solver 
please enter the data file name: dijkstra_solver.txt
file loaded.


How would you like to process your data file?
1.) shortest path
2.) minimum spanning tree
3.) Travelling Salesman

please enter 1,2,3 or Q to quit: 1

please enter the location name to start from:Location1

please enter the location name for the destination:Location5
distances and parents:
Location1 Location4 Location2 Location3 Location5

And you can verify yourself from the weights of the edges that this is indeed the shortest path from 1 to 5.

I think the problem might be related to having spaces between the names in the file. So, you might want to add some code to remove the leading or trailing space characters from the names you get from the file. You can do this the same way as with the removal of the parentheses.

mike_2000_17 2,669 21st Century Viking Team Colleague Featured Poster

I think that you are entering the wrong names, or something like that. If the names are not in name2v, the output will be 0, which is Location1, and if both are not found, then both the start and goal will be 0.

You should check again that the names are correct.

mike_2000_17 2,669 21st Century Viking Team Colleague Featured Poster

As I gave you the method to walk along the solution path on the other thread, here is the complete code (also removed some unnecessary junk, it is generally not a good idea to put together random pieces of code, you have to understand what you are doing):

#include <iostream>
#include <fstream>
#include <map>
#include <vector>
#include <string>
#include <boost/graph/adjacency_list.hpp>
#include <boost/graph/visitors.hpp>
#include <boost/graph/breadth_first_search.hpp>
#include <boost/graph/dijkstra_shortest_paths.hpp>
#include <boost/graph/metis.hpp>

typedef boost::adjacency_list_traits<
    boost::vecS, boost::vecS, boost::undirectedS, boost::listS> GraphTraits;
// type 'Vertex' identifies each vertex uniquely:
typedef GraphTraits::vertex_descriptor Vertex;

// Property type associated to each vertex:
struct VertexProperty {
    std::string name;  // Name of vertex (i.e., "location")
    Vertex predecessor; // Predecessor along optimal path.
    double distance; // Distance to the goal, along shortest path.
    boost::default_color_type color; // for use by dijkstra.

    VertexProperty(const std::string& aName = "") : name(aName) { };
};

// Property type associated to each edge:
struct EdgeProperty {
    double weight; // distance to travel along this edge.

    EdgeProperty(double aWeight = 0.0) : weight(aWeight) { };
};

// Type of the graph used:
typedef boost::adjacency_list<
  boost::vecS, // out-edges stored in vector 
  boost::vecS, // vertices stored in vector
  boost::undirectedS, // undirected graph (edge don't have a specific direction)
  VertexProperty, // properties associated to each vertex.
  EdgeProperty // properties associated to each edge.
  > Graph;
// Create a global graph object 'g'
Graph g;

// This is a visitor for the dijkstra algorithm. This visitor does nothing special.
struct do_nothing_dijkstra_visitor {
    template <typename Vertex, typename Graph>
    void initialize_vertex(Vertex u, const Graph& g) const …
mike_2000_17 2,669 21st Century Viking Team Colleague Featured Poster

Alright, I feel generous today. Here's the code for the part that constructs the graph:

std::map<std::string, Vertex> name2v;

std::getline(fin, tempString); //Vertices:
std::getline(fin, tempString); //Location1, Location2, ...
std::stringstream tempSS(tempString);
while (std::getline(tempSS,tempName1, ',')){
    name2v[tempName1] = add_vertex(VertexProperty(tempName1), g);
}
std::getline(fin,tempString); //Edges:
while (std::getline(fin,tempString)){ // (Location1, Location2, 6)
    //remove parentheses
    tempString.erase( tempString.begin(), tempString.begin() + tempString.find('(') + 1 );
    tempString.erase( tempString.begin() + tempString.find(')'), tempString.end() );
    std::stringstream temp_ss(tempString);
    std::getline(temp_ss, tempName1, ',');
    std::getline(temp_ss, tempName2, ',');
    temp_ss >> weight;
    add_edge(name2v[tempName1], name2v[tempName2], EdgeProperty(weight), g);
}

That's it.

mike_2000_17 2,669 21st Century Viking Team Colleague Featured Poster

The problem with add_edge(tempName1, tempName2, weight, g); is that the strings tempName1 and tempName2 are not vertex descriptors and weight is not an edge-property. These two problems make it so that the compiler does not find a function like that one (that takes two strings and a double).

The edge-property part is easy to solve, just do EdgeProperty(weight) instead of just weight.

The other problem is a bit harder (as I tried to explain earlier). The problem here is that you cannot refer to vertices by their name, you need to refer to them by vertex-descriptors (i.e., the Vertex type in your code), which is what the BGL uses to identify vertices of a graph (these are actually indices or pointers to a vertex, but that's not important). When you do add_vertex, it returns a vertex-descriptor to the newly created vertex. You need to record all those vertex-descriptors and associate them with the correct name. For that, just use a std::map<std::string, Vertex>. Then, all you'll have to do to create the edges is to retrieve, through that map, the vertex-descriptors corresponding to the names tempName1 and tempName2.

mike_2000_17 2,669 21st Century Viking Team Colleague Featured Poster

I don't recommend that you use the old-style boost::property properties for your vertices and edges. You should use bundled properties instead. To run the Dijkstra algorithm, you will need properties for "predecessor", "distance", "weight" (for edges), "index", and "color". So, you could use the following structs for the vertices and edges:

typedef boost::adjacency_list_traits<
  boost::vecS, boost::vecS, boost::undirectedS, boost::listS> GraphTraits;
typedef GraphTraits::vertex_descriptor Vertex;

struct VertexProperty {
  std::string name;
  Vertex predecessor;
  double distance;
  boost::default_color_type color;

  VertexProperty(const std::string& aName = "") : name(aName) { };
};

struct EdgeProperty {
  double weight;

  EdgeProperty(double aWeight = 0.0) : weight(aWeight) { };
};

As for the "index" map, you can use the identity-map because the vertex descriptors of a graph that uses vecS for VertexListS argument will be the same as the vertex index.

The last piece of the puzzle is the dijkstra visitor class. For a simple "do nothing" visitor, you can use this one:

struct do_nothing_dijkstra_visitor {
  template <typename Vertex, typename Graph>
  void initialize_vertex(Vertex u, const Graph& g) const { };
  template <typename Vertex, typename Graph>
  void examine_vertex(Vertex u, const Graph& g) const { };
  template <typename Edge, typename Graph>
  void examine_edge(Edge e, const Graph& g) const { };
  template <typename Vertex, typename Graph>
  void discover_vertex(Vertex u, const Graph& g) const { };
  template <typename Edge, typename Graph>
  void edge_relaxed(Edge e, const Graph& g) const { };
  template <typename Edge, typename Graph>
  void edge_not_relaxed(Edge e, const Graph& g) const { };
  template <typename Vertex, typename Graph>
  void finish_vertex(Vertex …
mike_2000_17 2,669 21st Century Viking Team Colleague Featured Poster

To input all the vertices, you should do it in two steps. First, you input the entire line into a string (using std::getline). Then, you put that string into a std::stringstream and you input each individual name using std::getline with the delimiter as ',' character. Like this:

std::string temp_str;
std::getline(std::cin, temp_str);
std::stringstream temp_ss(temp_str);
std::string temp_name;
while( std::getline(temp_ss, temp_name, ',') ) {
  std::cout << "Got name: " << temp_name << std::endl;
};

That should print every vertex name.

For the edges, you should do something similar to get the individual values (name1, name2, weight). You can eliminate the parentheses using the string's functions to find characters:

std::string temp_str;
std::getline(std::cin, temp_str);
// eliminate the parentheses:
temp_str.erase( temp_str.begin(), temp_str.begin() + temp_str.find('(') );
temp_str.erase( temp_str.begin() + temp_str.find(')'), temp_str.end() );
// then, put in string-stream:
std::stringstream temp_ss(temp_str);
std::string name1, name2;
double weight;
std::getline(temp_ss, name1, ',');
std::getline(temp_ss, name2, ',');
temp_ss >> weight;
// print results:
std::cout << "Got first name: " << name1 << std::endl;
std::cout << "Got second name: " << name2 << std::endl;
std::cout << "Got weight: " << weight << std::endl;

which should give you the names and weight of the edges.

Start by getting all that working, and then, worry about constructing the graph for calling the dijkstra algorithm in BGL.

mike_2000_17 2,669 21st Century Viking Team Colleague Featured Poster

What code do you have so far? We don't just do people's homeworks, you have to show that your are trying to solve the problem, and ask about specific problems that you are having with your code.

Hinata_Dev commented: the code I have is too long :/ +0
mike_2000_17 2,669 21st Century Viking Team Colleague Featured Poster

Being half-Swedish, I can testify that Xmas has very little to do with Christianity. Sweden is both one of the most atheistic countries (if not the most) and one with the most Xmas traditions. Sweden is also one of the last places to convert to Christianity in Europe, and many "Christian" holydays are Christian only by name, as most traditions are still mostly pagan (e.g., inspired by the worship of stars, the sun, the spring feast on the remaining winter preserves, dancing around the first flowers blooming in summer, etc..).

Xmas is called "Jul" in Sweden, which is a old norse mythological name for roughly the month around the winter solstice. There is no Santa Claus (uhmm.. spoiler alert!), I mean, the stories told to children is about the "Tomte" (or gnomes... yes, the same as those garden gnomes.. small old men with pointy red hats) which live in the mountains, each having a particular village attributed to them, for which they make gifts and distribute them to their village by cross-country skiing (or riding a Julbock) door-to-door on the 24th of december. Some also have the Julbock distribute the gifts, which is even more pagan / old-norse mythology (the goat is Thor's magical goat).

Xmas time starts with the advent candles. More importantly, there's Sankt Lucia which many people see as more important than Xmas day. It usually involves getting all the girls (children) from the local area to dress up in white robes and …

mike_2000_17 2,669 21st Century Viking Team Colleague Featured Poster

Jumping the cmos pin is not going to do anything to your hard-drive. This only resets the firmware and configuration of your bios to its original (factory) configuration. It will not affect the OS boot sequence, nor the OS installation itself. But I doubt that this would be a bios / firmware issue, especially if you did not do anything special with those. It sounds more like a hardware problem.

If your OS is Win-XP, consider changing it since the support for it will stop in a few months. If you don't have access to a newer Windows version (7-8) or the rig won't be able to handle it, consider installing a Linux distro instead, which is great way to give a second life to an old PC.

leds are still lit green, green orange, red

That seems like the most visible sign of a problem. LEDs don't change color for no reason, and I doubt the different colors are there for decorative purposes. You either have defective RAM sticks, or a defective motherboard.

The 2 system fans are wired a bit strange, they're pulling power (red/black leads) out of adapter blocks on one of the 4 pin power supply plugs, then a white lead is tapped into the fan's 3 pin connector and goes to the 3 pin terminal on the mobo.

I think this is a fairly common wiring, especially when an additional fan was introduced (e.g., to cool some overclocked components). However, it …

mike_2000_17 2,669 21st Century Viking Team Colleague Featured Poster

You made a typo on line 61:

glBindBuffer(GL_ARRAY_BUFFER, vertexId);

It should be:

glBindBuffer(GL_ARRAY_BUFFER, colorId);

Also, I think you should be using GL_TRIANGLE_STRIP instead of GL_TRIANGLES. See explanation or this page. You simply cannot have 8 vertices representing triangles (2 triangles = 6 points, 3 triangles = 9 points). You might also try the deprecated GL_QUADS instead (which, in this case, would draw two rectangles, one in front (z=1), one in back (z=-1)).

To draw the complete cube, using your 8 points (8 corners of a cube), you need to use the glDrawElements to provide a array of indices to order and reuse the points to make the complete mesh. For example, this could work:

static const GLsizeiptr PointsCount = 17;
static const GLubyte PointsData[] =
{
    0, 2, 1,
    7,
    4,
    6,
    5,
    3,
    0,
    2,
    3,
    7,
    6,
    5,
    4,
    0,
    1
};


//... everything else the same, until:

  glDrawElements(GL_TRIANGLE_STRIP, PointsCount, GL_UNSIGNED_BYTE, PointsData);

If I have done it correctly (ordering the vertices of the triangle-strip), then it should give you a cube.

Finally, in your draw function, you might want to add a translation, otherwise, you will have trouble seeing the cube because the camera is smack dead in the center of it. You should move back (using glTranslatef) a little bit before drawing the scene:

void draw()
{
    glClear(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT);

    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();

    glTranslatef(0.0, 0.0, -5.0);

    //...
mike_2000_17 2,669 21st Century Viking Team Colleague Featured Poster

Anyone that is concerned enough about security to commission a pentester would probably not make the blatant mistake of keeping flash players installed on their network's computers. Sounds more like you're trying to write a hack, and it seems you have a long way to go, so I won't be losing sleep over the possibility of your hack invading the world anytime soon.

I wish to help him do a patch (actually why I’s asked), but first chosed to get an exploit that suits that vulnerability.

That makes no sense at all. Pentesting is about finding vulnerabilities in an existing infrastructure, so that they can be patched. There is no point in doing pentesting on a vulnerability you have already found.

If you found a vulnerability in the adobe flash player program, then report it to Adobe, and you may even provide them with a patch. Unless you have bad intentions, this is the only logical next step.

Is the Ruby language a programming or a scripting language ??

Ruby is an interpreted / JIT-compiled language, it says so on the wiki page.

if u do a research on the meaning of pentesting before attempting to make an idiot of urself publicly ?

Says the person who never made it as far as the wiki-page about Ruby.

dat u see me write "the" as "d" (for abbreviation purpose), which u KNOW is dat y u should ask me to start writing in english(rather …

mike_2000_17 2,669 21st Century Viking Team Colleague Featured Poster

Last time i checked that is high treason.

Accusing a black person of high treason during the Apartheid is the very definition of irony.

mike_2000_17 2,669 21st Century Viking Team Colleague Featured Poster

With all these insane comparisons I hear from the right-wing of Hitler with atheists, Mandela or Obama, people will start to believe that Hitler was a black atheist communist!

(as opposed to reality: Hitler was a devout Christian, white-supremacist / nationalist, fascist / Nietzscheist, and vehemently and viciously anti-communist)

mike_2000_17 2,669 21st Century Viking Team Colleague Featured Poster

It's a matter of unfalsifiability. If a religion claimed that devotion or prayer could make you live forever, it would get disproven as soon as the first generation of devotees were all dead. But if you claim that the "soul" will ascend to a higher plane (e.g., budhist "enlightenment"), reincarnate into another being while conveniently losing all conscious memory of the past lifes (e.g., hinduism or scientology), or be transported to heaven or hell (e.g., abrahamic myths), then you conveniently avoid falsification because there is no way to disprove it. Any religion or myth that does not follow the basic logic of unfalsifiability will not survive very long, and so, natural selection makes it so that all surviving religions or myths have that in common, i.e., you can never prove them wrong (which also implies that you can never prove them right either).

mike_2000_17 2,669 21st Century Viking Team Colleague Featured Poster

Hi, and welcome!

mike_2000_17 2,669 21st Century Viking Team Colleague Featured Poster

That's a whole different story. I'm not sure whether you mean (1) you want to avoid creating an OpenGL window and just render to an image, or (2) you want to render to an image without "affecting" the framebuffer (for the stuff drawn to the screen).

But first, you have to understand a couple of things about OpenGL. Specifically, the difference between "device context" (DC), "rendering context" (RC) and "framebuffer" (FB), which is one of the most awkward parts of OpenGL's design. Let me draw you a little diagram:

      OS
      |
      DC  <---  RC  <---  glDraw..()
      |         |
      ---  FB ---

What I'm trying to represent here is that the Operating System (OS) creates and controls the device context, which acts as a kind access-point to the GPU to be able to draw things on a window (GUI) that the OS controls (Windows GDI, or Linux/Mac/Unix X Server). Then, in OpenGL, you can create a rendering context (glCreateContext) to match the DC and attach it to that DC (glMakeCurrent). The RC acts as an access-point between the application (where you make OpenGL calls to draw stuff, like glBegin() / glEnd()), and an execution context inside the GPU that can actually do the drawing. And finally, you have the frame-buffer, which is essentially the data structure shared by the DC and the RC, and which represents what is actually drawn to the screen (if the window is visible, not minimized, etc.). In other words, the FB is the …

mike_2000_17 2,669 21st Century Viking Team Colleague Featured Poster

Nobody is a saint. Most Saints were not saints. Even Ghandi had several darker sides to him (like his outspoken racism against African blacks).

Everyone is a mixed bag. Some good, some bad. If you have to tally it up, there is no doubt Mandela had a huge positive impact. Regardless of the more violent-rebelious nature of his early actions (pre-emprisonment), and the latest troubles with the ANC.

Elevating people to sainthood is not about some sort of mass-delusion to think that the guy is all good. It's about focusing on and being inspired by the good and the admirable parts of his legacy or life. Case in point, if you focus on "young Mandela", you might just see another "freedom front" leader, not the first, certainly not the last, and probably not much of an example to follow. But if you focus on the Mandela that ended Apartheid and de-fused much of the racial tensions through conciliation, mutual understanding, and forgiveness, then you can draw a lot of inspiration and it can certainly serve as an example to follow. The former is uninteresting, the latter is useful.

mike_2000_17 2,669 21st Century Viking Team Colleague Featured Poster

The question becomes is ME ths same as Anglo-Saxon?

No, ME comes much after Anglo-Saxon. Anglo-saxon is an antiquated term that refers to the Germanic settlers who came to the British Isles in the first millenium, before the Norman (French) invasion. Words of "Anglo-saxon" root are usually referred to with the more precise and modern term "Old German" in most dictionaries. And Middle English is essentially the language spoken in Britain after the significant mixing of French from the Norman invaders / occupiers (from 1066 and on).

I don't like the term Anglo-saxon because it attempts to re-write history to make it sound as though it was a mix of "Anglo" (i.e., the "English people") and "Saxons" (i.e., a small ground of immigrants from modern-day Netherlands / north-west Germany). It's a classic case of Anglo-centric re-writing of history. It attempts to deny the fact that the British Isles were essentially a part of the Viking empire for several hundred years (until the Norman invasion), and that even before the Vikings era, much of the population came from Scandinavian and Germanic areas. British historians have a long history of re-writing history to reflect the nationalistic view that the "English people" were always there and mostly ruled their own land (only admitting to short-lived invasions). The reality is quite different, but few history books will tell you that, mostly because they haven't been updated in a while.

English is a Germanic language with very strong French influence. About 70% of …

Reverend Jim commented: Interesting +0