[QUOTE=RyanDv3;33288415]Seems to me you'd be better off summing the primary and secondary weights in some way, but if you absolutely must minimize the primary one, then I'd just do that and then, in the case of a tie, sum and then compare the secondary costs of the two paths.[/QUOTE]
The first cost is critical and [i]must[/i] be minimized (as example, think of it as time spent for transfer in an extremely time-critical application). The second one comes secondary and should be minimized if possible (think of this as being the transfer cost which varies depending on route - should be minimized if possible, but never at the expense of time).
The problem here is that this method involves finding [i]all[/i] paths from A to B with the same minimum primary cost. How would I go about doing that? Isn't there a more efficient way?
[editline]15th November 2011[/editline]
[QUOTE=RyanDv3;33288415]
Seems like it wouldn't have much of an effect though; I imagine it's somewhat rare to get path cost ties.[/QUOTE]
That entirely depends on the graph in question. Let's say a lot of nodes have the exact same cost to each of their neighbours - which isn't unfeasible and might give several ties.
What method are you using to find paths?
[QUOTE=RyanDv3;33288663]What method are you using to find paths?[/QUOTE]
That's what I'm trying to find out. Finding [i]one[/i] shortest path between two nodes is fairly simple, finding [i]all[/i] shortest paths between two nodes is in essence what I'm asking about.
Can you tell what exactly it is that you are doing?
Generally, finding the absolute shortest path in unfeasible, which is why algorithms that employ heuristics exist. Like A*. So your "I must find ALL shortest paths" stuff is kinda meaningless.
If your precision allows it, and the path doesn't contain any edges whose weight is 0, you could try this:
Call the smallest primary edge weight [i]D[/i]. Calculate a secondary weight factor [i]k[/i] so that the secondary weights of the longest path that might emerge don't add up to [i]D[/i], i.e. they will never have an impact great enough to override the primary costs.
One way to choose the factor [i]k[/i] could be:
[img]http://latex.codecogs.com/gif.latex?0%20%3C%20k%20%3C%20\frac{D}{S}[/img]
where S is the sum of the secondary costs of every edge. This should make it work for every path that doesn't traverse a node more than once.
Then the cost of an individual edge is [i]Primary + k * Secondary[/i]
No offense, but it sounds like all your questions would be answered by simply implementing a normal pathfinding algorithm. You're over-thinking things, I think.
@anonim
[QUOTE=Anonim;33288756]finding [i]all[/i] shortest paths between two nodes is in essence what I'm asking about.[/QUOTE]
But there's only one shortest path between two nodes.
[QUOTE=Jookia;33288932]But there's only one shortest path between two nodes.[/QUOTE]
You're on the surface of a perfect sphere. Your destination lies exactly on the other side of the sphere.
How many shortest paths are there to your destination?
[sp]Infinite[/sp]
[QUOTE=Jookia;33288932]But there's only one shortest path between two nodes.[/QUOTE]
I guess a circle might have cases where there's two equal shortest paths...
But if you wanted to have some secondary cost, like maybe the circle has wind blowing clockwise, then you would NOT find both shortest paths by distance and then "break the tie" by looking at wind resistance; you just add in the cost of going against the wind.
I see no reason you can't sum your primary and secondary costs unless the secondary cost [b]doesn't matter[/b], in which case, why are you even bothering with it??
[QUOTE=ThePuska;33288983]You're on the surface of a perfect sphere. Your destination lies exactly on the other side of the sphere.
How many shortest paths are there to your destination?
[sp]Infinite[/sp][/QUOTE]
Fuck.
[QUOTE=Ehmmett;33288981]what's the type of collision called where you check if a point(x,y), is inside of an object(x,y,w,h)?
just for curiosity/naming sake.[/QUOTE]
I'd go for Shape.Contains(Point) most likely.
[QUOTE=RyanDv3;33288877]Can you tell what exactly it is that you are doing?
Generally, finding the absolute shortest path in unfeasible, which is why algorithms that employ heuristics exist. Like A*. So your "I must find ALL shortest paths" stuff is kinda meaningless.[/QUOTE]
Routing metrics. The constraint here is that the absolute minimum time needs to be spent from A to B, while the cost should be minimized wherever possible, but never at the expense of the time spent. Precision is prioritized over the time spent to actually calculate the path, so A* isn't really an option.
[QUOTE=Jookia;33288932]But there's only one shortest path between two nodes.[/QUOTE]
Not necessarily. There may be several paths to the same node with the same net cost. Thus there must necessarily be a possibility that multiple shortest paths may occur.
[QUOTE=ThePuska;33288890]If your precision allows it, and the path doesn't contain any edges whose weight is 0, you could try this:
Call the smallest primary edge weight [i]D[/i]. Calculate a secondary weight factor [i]k[/i] so that the secondary weights of the longest path that might emerge don't add up to [i]D[/i], i.e. they will never have an impact great enough to override the primary costs.
One way to choose the factor [i]k[/i] could be:
[img]http://latex.codecogs.com/gif.latex?0%20%3C%20k%20%3C%20\frac{D}{S}[/img]
where S is the sum of the secondary costs of every edge. This should make it work for every path that doesn't traverse a node more than once.
Then the cost of an individual edge is [i]Primary + k * Secondary[/i][/QUOTE]
This seems like a reasonable and simple solution. Thanks.
I'm having a big problem with OpenSSL and WinSock
[code]
#include "openssl/ssl.h"
#include "iostream"
#include <cstdio>
#include <iostream>
#include <string.h>
#include <errno.h>
#include <sys/types.h>
#include <windows.h>
using namespace std;
#pragma comment(lib, "Ws2_32.lib")
#define BUFSIZE 500
char buf[BUFSIZE];
char *msg;
WSADATA wsda;
int sock;
struct hostent *host;
struct sockaddr_in server_addr;
short int s_port = 993;
const char *s_ipaddr = "74.125.79.108";
int SSL_library_init();
SSL_METHOD *meth;
int main () {
SSL_load_error_strings();
SSL_library_init();
//RAND_seed(buf, BUFSIZE);
SSL_CTX *sslContext = SSL_CTX_new(SSLv23_client_method());
if (sslContext == NULL)
{
cout << "err\n";
}
SSL *sslConnection = SSL_new(sslContext);
if(sslConnection == NULL)
{
cout << "err\n";
}
WSAStartup(MAKEWORD(2,2), &wsda);
sock = socket(AF_INET, SOCK_STREAM, IPPROTO_IP);
server_addr.sin_family = AF_INET;
server_addr.sin_port = htons(s_port);
server_addr.sin_addr.s_addr = inet_addr(s_ipaddr);
if(server_addr.sin_addr.s_addr == INADDR_NONE)
{
host = NULL;
host = gethostbyname(s_ipaddr);
if(host == NULL)
{
return false;
}
memcpy(&server_addr.sin_addr, host->h_addr_list[0], host->h_length);
}
connect(sock, (struct sockaddr *) &server_addr, sizeof(server_addr));
SSL_set_fd(sslConnection, sock);
SSL_connect(sslConnection);
cout << "Connecting:\n";
SSL_read(sslConnection, buf, sizeof(buf)-1);
cout << buf << "\n";
cout << "Logging-in:\n";
msg = "a login kilkilerr45@gmail.com *CENSORED*\n ";
SSL_write(sslConnection, msg, strlen(msg));
SSL_read(sslConnection, buf, sizeof(buf)-1);
cout << buf << "\n";
cout << "INBOX\n";
msg = "a SELECT INBOX\n";
SSL_write(sslConnection, msg, strlen(msg));
SSL_read(sslConnection, buf, sizeof(buf)-1);
cout << buf << "\n";
system("pause");
}
[/code]
And here it is the result, it seems to hang on SSL_Read(); like it was disconnected or something
[code]
Connecting:
* OK Gimap ready for requests from 213.146.62.20 c56if8862464eei.8
Logging-in:
* CAPABILITY IMAP4rev1 UNSELECT IDLE NAMESPACE QUOTA ID XLIST CHILDREN X-GM-EXT-
1 UIDPLUS COMPRESS=DEFLATE
a OK kilkilerr45@gmail.com sdafasdf dfasd authenticated (Success)
INBOX
[/code]
So the problem is after I SSL_Write() and SSL_Read(); I get disconnected and the program hangs
[QUOTE=calzoneman;33288102]Through experimentation with telnet, your server refuses my connection unless I add the request header
[code]
Accept: text/html
[/code]
That would make the entire request
[code]
GET /data/test.txt HTTP/1.1
Host: www.novaember.com
Accept: text/html
[/code][/QUOTE]
Thanks, that helped!
Tho at first it only did with large files, the Accept parameter is what I needed to know. Only problem is that it sends header data as well but Im sure I can filter that later.
Now lets hope this waa my last problem...
[QUOTE=Anonim;33289205]
This seems like a reasonable and simple solution. Thanks.[/QUOTE]
[quote=me]Seems to me you'd be better off summing the primary and secondary weights in some way[/quote]
whatever...
[QUOTE=RyanDv3;33289263]whatever...[/QUOTE]
Well, yes. Didn't think of such a straight-forward method at first.
I'm trying to figure out how to pass a 2d array into a thread in C
Here's some of the code:
[code]struct thread_data_s{
pthread_t thread;
pthread_mutex_t *parrent_mutex;
pthread_mutex_t wait_mutex;
int i;
double *t;
double *t1;
double **a;
double *b;
double errori;
int working;
int quit;
};
double a[n][n];
for(int i = 0; i < threads; i++){
thread_data[i].parrent_mutex = &parrent_mutex;
pthread_mutex_init(&(thread_data[i].wait_mutex), NULL);
//Pointers to matrix data
thread_data[i].t = t;
thread_data[i].t1 = t1;
thread_data[i].a = (double **)a;
thread_data[i].b = b;
thread_data[i].errori = 0.0;
thread_data[i].working = 0;
thread_data[i].quit = 0;
pthread_create(&(thread_data[i].thread), NULL, worker, (void *)&thread_data[i]);
}[/code]
It compiles without errors, but I must be doing something wrong because when I try to access the array from the thread it segfaults.
A true 2D array isn't the same as an array of pointers to more arrays. (The latter is sometimes called a "ragged array".)
I'm suspicious of that (double **) cast — if you had to put that in to make the code compile, it means you're forcing a cast to an incompatible type.
Guess its not that easy..
Does anyone know how to extract the body from a raw HTTP request? (One that includes headers as well as something after the body) (In Lua)
Ive already found out that there are special sequences of characters before and after the body;
Before: 52, 10, 13 (Number 4, Line Feed, Carriage Return)
After: 48, 10, 13 (Number 0, Line Feed, Carriage Return)
[QUOTE=Ehmmett;33295338]Need help understanding:
-snip-
It's beyond me how or why this code works, or what it [I]really[/I] does. :/[/QUOTE]
It creates a table that uses the Account table as it's index, so that if you try to access a function/value it doesn't have, it will try to find it in the Account table instead.
[QUOTE=Ehmmett;33302847]Could you explain step by step how that works?[/QUOTE]
Metatables are basically tables that contain functions that are called automatically under special circumstances, such as when two tables (with the same metatable) are added together with the "+" operator, when it's deallocated by the garbage collector, etc.
Example:
[code]
-- Create the vector metatable.
VectorMeta = {}
-- Create a function to be called when two vectors are added together.
function VectorMeta.__add(a, b)
return {x = a.x + b.x, y = a.y + b.y}
end
-- Create two vectors.
vector1 = {x = 2, y = 3}
vector2 = {x = 5, y = 6}
-- Set the vectors' metatable to vectorMeta.
setmetatable(vector1, VectorMeta)
setmetatable(vector2, VectorMeta)
-- Add vector1 and vector2 together, this will call __add in the VectorMeta table.
vector3 = vector1 + vector2
-- Print out the result.
print(vector3.x, vector3.y)
[/code]
That's basically how metatables work, here I demonstrated the _add function, but there are multiple metamethods that you can use, for example:
__add
__sub
__gc
__tostring
__index
...
The __index "metamethod" is really useful, you set it to a table and it will look inside that table if it can't find the index you're accessing.
Example:
[code]
Account = {} -- Account table.
Account.mt = {__index = Account} -- Account metatable.
function Account.create()
local result = {balance = 0} -- Creates a table with balance set to 0.
setmetatable(result, Account.mt) -- Sets the table's metatable to Account.mt
return result
end
function Account:setBalance(balance)
self.balance = balance
end
function Account.mt:__tostring()
return "Account(" .. self.balance .. ")"
end
a1 = Account.create() -- Creates an account with it's metatable set to Account.mt, and with a balance of 0.
a1:setBalance(123) -- Set a1's balance member to 123, note that setBalance actually isn't a member of a1, but Lua will look for it in Account since it's metatable has it's __index set to Account.
print(a1) -- __tostring in Account.mt will be called here, __tostring will return "Account(123)", and that's what it will print.
[/code]
It's like operator overloading I guess.
Okay, so I ragequitted.
Im now using a more simple method because I just didnt know how to make it able to handle big files. Because with the code I had, it either hangs or doesnt download everything.
Fuck that
Anyway, Im using http.request now with a custom step handler. Threads to not freeze while downloading.
I remember having a question when I started writing this.
I forgot it.
Fuck that
(PS. Ill edit when I remember my question)
Im using SFML 2.0 and im trying to use pure OpenGL with SFML stuff
however when I draw stuff and then use SaveGLStatess I get an error:
[quote]
An internal OpenGL call failed in Renderer.cpp (77) : GL_INVALID_VALUE, a numeric argument is out of range
[/quote]
Renderer.cpp 77 is(first line in SaveGLStates):
[cpp]GLCheck(glPushAttrib(GL_ALL_ATTRIB_BITS));[/cpp]
The last thing I do before calling saveStates is:
[cpp]void d3Sprite::Draw()
{
// 1rst attribute buffer : vertices
glEnableVertexAttribArray(positionID);
glBindBuffer(GL_ARRAY_BUFFER, vertexbuffer);
glVertexAttribPointer(
positionID, // attribute 0. No particular reason for 0, but must match the layout in the shader.
3, // size
GL_FLOAT, // type
GL_FALSE, // normalized?
0, // stride
(void*)0 // array buffer offset
);
glUseProgram(shader.shaderID);
// Send our transformation to the currently bound shader,
// in the "MVP" uniform
// For each model you render, since the MVP will be different (at least the M part)
glUniformMatrix4fv(MatrixID, 1, GL_FALSE, &MVP[0][0]);
// Draw the triangle !
glDrawArrays(GL_TRIANGLES, 0, 6); // Starting from vertex 0; 6 vertices total -> 2 triangles
glDisableVertexAttribArray(positionID);
}[/cpp]
[QUOTE=Darkwater124;33300953]Does anyone know how to extract the body from a raw HTTP request? (One that includes headers as well as something after the body) (In Lua)[/QUOTE]
HTTP Responses are formatted something similar to the HTTP request; that is, a header line saying the result code and HTTP version (nearly ubiquitously HTTP/1.1 nowadays), a set of "Property: Value" lines saying things like setting cookie values and keeping connections open, then some whitespace and the body. There is no footer.
Once you've got your response from the server, you can split the result into basically two parts, the header and the body. Those two parts are separated by \r\n\r\n . So just split the result string by those and take the second part and that [i]should[/i] be the body. If the body contains \r\n itself it might stuff up a little so you'll probably need to work with this a bit but that's the theory.
If you feel like looking into the technical details there's a [url=http://www.w3.org/Protocols/rfc2616/rfc2616-sec6.html]standards document[/url] for it.
My Professor said you should [B]never[/B] use the break statement, and you should always set the loop condition to false to break out of the loop.
I thought this was kind of bizarre because I've never found a problem with break. And setting the conditional to false would finish the current loop and could cause some errors or logic errors.
Is my professor correct?
[QUOTE=thisBrad;33309490]My Professor said you should [B]never[/B] use the break statement, and you should always set the loop condition to false to break out of the loop.
I thought this was kind of bizarre because I've never found a problem with break. And setting the conditional to false would finish the current loop and could cause some errors or logic errors.
Is my professor correct?[/QUOTE]
I think blanket rules like ALWAYS do or NEVER do xyz are generally pretty stupid. In this case, I'd vehemently disagree with your professor. Sometimes the use of a break statement makes logic significantly clearer than attempting to use the loop condition.
Consider:
[cpp]
bool loopCond = true;
while(loopCond)
{
if(someFailureCondition)
loopCond = false;
else if(someOtherFailureCondition)
loopCond = false;
if(loopCond) // extraneous if statement
{
// huge piles of code
}
}
// Versus
while(true)
{
if(someFailureCondition)
break;
else if(someOtherFailureCondition)
break;
// Tada, useless if statement now avoided through judicious use of break
// huge piles of code
}
[/cpp]
If he's advocating the use of loop condition variables so that you can exit multiple nested loops cleanly you can just as easily achieve this with a goto - as dirty as it may seem goto is a valid solution and as long as it is well signposted with comments it's not the be-all-and-end-all issue that everyone decries it as being.
I need to help teach my FIRST Robotics team C++, and I'm a shit teacher. What's a good website for learning C++? Most of the programmers know java, if that makes any difference.
[QUOTE=Phyxius;33310628]I need to help teach my FIRST Robotics team C++, and I'm a shit teacher. What's a good website for learning C++? Most of the programmers know java, if that makes any difference.[/QUOTE]
[url=http://www.cplusplus.com/doc/tutorial/]Here[/url]. Also, since they know Java, I'm betting they'll just fly through it.
[QUOTE=thisBrad;33309490]My Professor said you should [B]never[/B] use the break statement, and you should always set the loop condition to false to break out of the loop.[/QUOTE]
Oh, and another thing: Sure you mention break specifically in the context of loops here, but from the way you've worded it it sounds like your professor doesn't want you to use the break keyword [i]ever[/i].
In that scenario, how would this Professor of yours do switch statements?
[cpp]
switch(someChar)
{
case 'a':
if(someChar == 'a') { blah++; }
case 'b':
if(someChar == 'b') { blah++; }
case 'c':
if(someChar == 'c') { blah++; }
// ...
}
[/cpp]
:suicide:
[QUOTE=mechanarchy;33311047]In that scenario, how would this Professor of yours do switch statements?
[cpp]
switch(someChar)
{
case 'a':
if(someChar == 'a') { blah++; }
case 'b':
if(someChar == 'b') { blah++; }
case 'c':
if(someChar == 'c') { blah++; }
// ...
}
[/cpp]
:suicide:[/QUOTE]
Silly mechanarchy, that code doesn't need the overhead of switch statements.
Sorry, you need to Log In to post a reply to this thread.