Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Post
  • Reply
ShoulderDaemon
Oct 9, 2003
support goon fund
Taco Defender

YO MAMA HEAD posted:

I'm trying to convert a nice C-style math expression like (t*9&t>>4|t*5&t>>7|t*3&t/1024)-1 so that it can be understood correctly by a Smalltalk-esque language with no Order of Operations. I'm sure this can be done with regular expressions, but I'm kind of poo poo at them at the best of times and it's getting late. I know the general sense of things is that parentheses will need to be inserted all over the place, but I can't quite wrap my brain around it.

I also suspect that there are other solutions here—I've read some about Shunting Pierce, but I think that would just take me to RPN (not super helpful).

e: What the correct interpretation of the above equation be (((t*9)&(t>>4))|((t*5)&(t>>7))|((t*3)&(t/1024)))-1 ?

It's really late at night so I may be out of my mind, but as I recall if you first use a regular substitution like s/([^+]+)\+(.+)/($1+$2)/g to put parenthesis around the lowest-order-of-operations operators, then something like s/([^+*]+)\*([^+]+)/($1*$2)/g to put parenthesis around the next-highest-order-of-operations operators, then something like s/([^+*^]+)\^([^+*]+)/($1^$2)/g for the next-highest and so on and so forth, then you'll wind up with a correctly-parenthesized expression. I suspect this technique relies on there being no parenthesis in the expression to start with, and all the operators being left-associative. As I said, really late at night, I haven't tested this, no promises.

But converting to an intermediate form like RPN is a way more normal way of handling this kind of problem. Regular expressions are not really a natural solution.

Edit: If you don't understand how RPN helps you, consider the expression 3+(4-2)*5. We can translate this to RPN, giving us the list [3, 4, 2, -, 5, *, +]. Reverse that list to give us [+, *, 5, -, 2, 4, 3]. Consider the algorithm:

code:
unstack:
  x <- pop the stack
  if x is a number,
    return that number
  otherwise, x is an operator,
    r <- unstack
    l <- unstack
    return "(" + l + " " + x + " " + r + ")"
When run on the stack [+, *, 5, -, 2, 4, 3], it looks like:

code:
stack = [+, *, 5, -, 2, 4, 3]
unstack pops +, an operator
  unstack pops *, an operator
    unstack pops 5, a number
      return "5"
    unstack pops -, an operator
      unstack pops 2, a number
        return "2"
      unstack pops 4, a number
        return "4"
      return "(4 - 2)"
    return "((4 - 2) * 5)"
  unstack pops 3, a number
    return "3"
  return "(3 + ((4 - 2) * 5))"
Which is, indeed, correct.

ShoulderDaemon fucked around with this message at 10:58 on Mar 22, 2012

Adbot
ADBOT LOVES YOU

The Born Approx.
Oct 30, 2011
Dumb question, but what is the difference between a library and an object file, and why should I choose to use one over the other? It seems to me they serve the same purpose - to provide a definition of functions/subroutines that you'd want to be able to use in multiple programs without rewriting them. And for that matter, what is the difference between a lib*.so, and a lib*.a?

ultrafilter
Aug 23, 2007

It's okay if you have any questions.


YO MAMA HEAD posted:

I'm trying to convert a nice C-style math expression like (t*9&t>>4|t*5&t>>7|t*3&t/1024)-1 so that it can be understood correctly by a Smalltalk-esque language with no Order of Operations. I'm sure this can be done with regular expressions, but I'm kind of poo poo at them at the best of times and it's getting late. I know the general sense of things is that parentheses will need to be inserted all over the place, but I can't quite wrap my brain around it.

I also suspect that there are other solutions here—I've read some about Shunting Pierce, but I think that would just take me to RPN (not super helpful).

e: What the correct interpretation of the above equation be (((t*9)&(t>>4))|((t*5)&(t>>7))|((t*3)&(t/1024)))-1 ?

Build a parse tree and print it with all the extra parentheses. There's almost certainly a bunch of canned parsers for arithmetic expressions out there already, so just use one of those to get the tree.


The Born Approx. posted:

Dumb question, but what is the difference between a library and an object file, and why should I choose to use one over the other? It seems to me they serve the same purpose - to provide a definition of functions/subroutines that you'd want to be able to use in multiple programs without rewriting them. And for that matter, what is the difference between a lib*.so, and a lib*.a?

A library is a bunch of object files. It's customary to release things as libraries so there's only one file (plus whatever definitions you need), but there's no technical reason why you have to.

YO MAMA HEAD
Sep 11, 2007

Okay, I'll try the RPN solutions! It's worth pointing out that I'm a computer musician, not a computer scientist, and so my background on this kind of stuff is a little iffy—it sometimes seems like doing too much CS work just isn't worth it. Thanks for thoughts!

Standish
May 21, 2001

The Born Approx. posted:

And for that matter, what is the difference between a lib*.so, and a lib*.a?
libX.so is a dynamic library which can be linked at runtime. libX.a is a static library -- at compile time the functions in libX.a are copied into the resulting program executable and become an integral part of it. This has a number of consequences:
  • you can't upgrade the program and the library separately -- if you find a bug in your statically linked PNG decoder you have to upgrade all of Photoshop (but on the other hand updating your PNG decoder to fix a Photoshop bug won't break your web browser)
  • different programs can no longer use the same copy of the library, thus wasting disk space/memory
  • statically linked programs are slightly faster because of the dynamic library overhead of calculating all the offsets and memory addresses at runtime
There is an excellent series of articles linked from here by the guy who wrote the gold linker explaining all the ins and outs of linking.

Standish fucked around with this message at 20:50 on Mar 22, 2012

oRenj9
Aug 3, 2004

Who loves oRenj soda?!?
College Slice
I have a strange PHP question. I was working with some legacy (from like 2006) PHP code. Our SVN server has a precommit hook that runs php -l on all of the committed php files to ensure that they compile fine.

I ran into an issue during an import where a script wouldn't compile. There were duplicate constants named in the same class. The code looked something like:

php:
<?
class DeviceIDs {
  /** Master device constants **/
  const DATA = "\x44"; // turn off streaming
  [other constants]
  /** Slave device constants **/
  const DATA = "\x44"; // turn off streaming
}
?>
My question is, are there any older versions of PHP where this would have compiled just fine or is this a compiler error that has been in production software for six years now?

Edit: It turns out that this compiles just fine on php 5.0.4, but not newer versions.

oRenj9 fucked around with this message at 21:33 on Mar 22, 2012

ToxicFrog
Apr 26, 2008


The Born Approx. posted:

Dumb question, but what is the difference between a library and an object file, and why should I choose to use one over the other? It seems to me they serve the same purpose - to provide a definition of functions/subroutines that you'd want to be able to use in multiple programs without rewriting them.

Well, the big difference is that a library is - as you say - a collection of functions/subroutines that you'd want to be able to use in multiple programs without rewriting them (and what form any particular library takes is dependent on the language, tools, and OS being used), whereas an object file is an intermediate stage in the build process for C/C++ and some other compiled languages.

In C/++ specifically, an object file is the machine code resulting from compilation of a single source file; it may later be used in linking to create a library or executable program, but isn't either yet. (Standish has nicely explained the difference between static and dynamic libraries.)

As for why you'd use libraries over object files, for dynamic libraries the reason is obvious - object files can't be dynamically loaded directly, they need the additional information added by the linker when it creates the .so. For static libraries, it's easier to manage one file than a dozen (and in fact .a static libraries are just simple ar archives containing all the object files making up the library).

In many languages the question never arises; in most interpreted languages, for example, libraries are simply distributed as source code which the interpreter loads directly - there is no distinction between the library and the source code for the library.

Maniaman
Mar 3, 2006
Going along with my project from the last page, I figure while I'm waiting on hardware and relay boards to arrive I can at least start some of the programming.

I'm having a hard time with this because I'm not even sure what you would call it, but can someone point me in the right direction to get started on a "waiting list" system that only gives 1 person control of the hardware at a time, and everyone else has to wait in line? I did some googling for php waiting list but it wasn't really what I was looking for.

I basically need a way to keep track of all the sessions, and add them all to a list (or probably a database) for the waiting list, and as the timer runs out on the active session, pick the next entry from the waiting list and transfer control to them. I'm just having a hard time putting it to code, as I've never really done a lot with session management before.

baquerd
Jul 2, 2007

by FactsAreUseless

Maniaman posted:

I'm having a hard time with this because I'm not even sure what you would call it, but can someone point me in the right direction to get started on a "waiting list" system that only gives 1 person control of the hardware at a time, and everyone else has to wait in line? I did some googling for php waiting list but it wasn't really what I was looking for.

I basically need a way to keep track of all the sessions, and add them all to a list (or probably a database) for the waiting list, and as the timer runs out on the active session, pick the next entry from the waiting list and transfer control to them. I'm just having a hard time putting it to code, as I've never really done a lot with session management before.

This is not a trivial problem, you have to be aware of concepts related to databases, concurrency, and client/server communications.

You mentioned a database and this is an acceptable method, and probably one of the simplest to implement cross-session blocking (another method would be a client/server daemon). Below is my simple hackish implementation (there are more elegant/maintainable/robust/etc solutions out there in either format).

When a new client connects to your website and requests access, your code will insert them into a waiting list at the end of the list. The user will be redirected to a page that allows them to click a button to check and see if they have access, if they do they get control. They will have another button to relinquish a control and there will be a time limit for both overall usage and for time since last action by the user controlling the crane.

First you need to install a database, try MySQL because it's free and easy to setup. Make a table craneWaitingList or whatever you like, with an autoincremented queuePosition (int) field and an identifier (char(23)) field. Make a table called craneUsage with an identifier (char(23), startUsage (datetime) and a lastUsage (datetime) field.

Create the page that allows the user to enter into the waiting list. This page will insert a unique identifier value for the client into the table. The autoincrement property of the table will automatically put them at the end of the queue. Make sure to store the unique identifier in a session variable. Generate the unique identifier with PHP's uniqid with more entropy.

Create the page the user is redirected to to request access to the crane (or make this a dynamic part of the first page). When the user requests access, first check for timeouts by checking the craneUsage table for tolerance values for startUsage and lastUsage. If the tolerance values are exceeded and identifier at the front of the queue matches the identifier in the craneUsage table, remove the row from craneWaitingList by deleting on the craneUsage identifier. This process should be done in a single transaction.

Next, select the minimum queuePosition from the table and match the identifier stored in the database with the current client identifier. If they match, grant the user access by first updating the craneUsage table with the identifier and new start values, and then by redirecting him to the control page.

On the control page, make sure to update the craneUsage table when controls are used. The button to relinquish control removes their identifier row from the craneWaitingList table.

floWenoL
Oct 23, 2002

YO MAMA HEAD posted:

I'm trying to convert a nice C-style math expression like (t*9&t>>4|t*5&t>>7|t*3&t/1024)-1 so that it can be understood correctly by a Smalltalk-esque language with no Order of Operations. I'm sure this can be done with regular expressions, but I'm kind of poo poo at them at the best of times and it's getting late. I know the general sense of things is that parentheses will need to be inserted all over the place, but I can't quite wrap my brain around it.

I also suspect that there are other solutions here—I've read some about Shunting Pierce, but I think that would just take me to RPN (not super helpful).

e: What the correct interpretation of the above equation be (((t*9)&(t>>4))|((t*5)&(t>>7))|((t*3)&(t/1024)))-1 ?

You can't use (normal) regular expressions to correctly parenthesize a context-free language, which arithmetic expressions are.

Edit: Ugh, beaten by new page!

Strong Sauce
Jul 2, 2003

You know I am not really your father.





Maniaman posted:

Going along with my project from the last page, I figure while I'm waiting on hardware and relay boards to arrive I can at least start some of the programming.

I'm having a hard time with this because I'm not even sure what you would call it, but can someone point me in the right direction to get started on a "waiting list" system that only gives 1 person control of the hardware at a time, and everyone else has to wait in line? I did some googling for php waiting list but it wasn't really what I was looking for.

I basically need a way to keep track of all the sessions, and add them all to a list (or probably a database) for the waiting list, and as the timer runs out on the active session, pick the next entry from the waiting list and transfer control to them. I'm just having a hard time putting it to code, as I've never really done a lot with session management before.

Essentially you need to create a queue. I don't know if you really need to use a database but MySQL/SQLite should get it done. What you should do is have the site have a page that does long poll requests for each client connected (there shouldn't be much problem as long as the site isn't hit very hard) which is essentially the waiting room area. When it is their turn to control the crane send some response back through and have your code redirect them to another page. On that page check to make sure that the sessions match and if they don't throw the client back out into the waiting room. And then of course once that session's time limit is up, remove them from the front of the queue, boot them off the control page and then repeat the process.

Look Around You
Jan 19, 2009

I think a big thing that people don't understand is that regular expressions are useful sometimes, but they're not exactly a "one size fits all" tool for parsing poo poo. Some things are good to use them for, some things you can use them for but it's not exactly practical (ISBN thing from a page or two back), and some things are simply not possible to use them with (parsing XML and poo poo).

ShoulderDaemon
Oct 9, 2003
support goon fund
Taco Defender

Look Around You posted:

and some things are simply not possible to use them with (parsing XML and poo poo).

Unless you use Perl, where the "regular" in "regular expression" is taken to mean something entirely different, apparently. But the use of general recursion in regular expressions probably belongs in the coding horrors thread rather than here.

baquerd
Jul 2, 2007

by FactsAreUseless

Strong Sauce posted:

Essentially you need to create a queue. I don't know if you really need to use a database but MySQL/SQLite should get it done. What you should do is have the site have a page that does long poll requests for each client connected (there shouldn't be much problem as long as the site isn't hit very hard) which is essentially the waiting room area. When it is their turn to control the crane send some response back through and have your code redirect them to another page. On that page check to make sure that the sessions match and if they don't throw the client back out into the waiting room. And then of course once that session's time limit is up, remove them from the front of the queue, boot them off the control page and then repeat the process.

PHP does have a global ENV space that could be used to maintain the queue, but you'd need to synchronize access to it or you have a race condition and PHP doesn't seem to have great utilities for that. Maybe I'm being pedantic as there really won't be many opportunities for a race condition on a very low traffic site and as long as you authenticate on crane commands as well it would be by far the simplest solution if you don't mind a user getting booted after apparently being granted access every once in a blue moon.

He could use a Java servlet and applet combo to make this really smooth but that's probably more than he wants to get into right now.

Edit: it seems PHP resets ENV variables set by the client after the current request. Not sure if this is possible without using external daemon or database in PHP.

baquerd fucked around with this message at 07:05 on Mar 23, 2012

Strong Sauce
Jul 2, 2003

You know I am not really your father.





baquerd posted:

PHP does have a global ENV space that could be used to maintain the queue, but you'd need to synchronize access to it or you have a race condition and PHP doesn't seem to have great utilities for that. Maybe I'm being pedantic as there really won't be many opportunities for a race condition on a very low traffic site and as long as you authenticate on crane commands as well it would be by far the simplest solution if you don't mind a user getting booted after apparently being granted access every once in a blue moon.

He could use a Java servlet and applet combo to make this really smooth but that's probably more than he wants to get into right now.

Edit: it seems PHP resets ENV variables set by the client after the current request. Not sure if this is possible without using external daemon or database in PHP.
I don't know if you're just referring to the part about not using a database or the whole post. What I meant was if the site's not meant for a lot of users he could save a lot of time with a text file. I would guess that PHP blocks the file while another process is writing to it so probably not ideal for a large number of users, otherwise yeah a database would be ideal.

I think all this is a little moot since I just realized he probably wants some sort of video to show the crane moving and that at least requires a flash app or a java app.

baquerd
Jul 2, 2007

by FactsAreUseless

Strong Sauce posted:

I don't know if you're just referring to the part about not using a database or the whole post. What I meant was if the site's not meant for a lot of users he could save a lot of time with a text file. I would guess that PHP blocks the file while another process is writing to it so probably not ideal for a large number of users, otherwise yeah a database would be ideal.

I think all this is a little moot since I just realized he probably wants some sort of video to show the crane moving and that at least requires a flash app or a java app.

Good call on the flat file for really low traffic, there's a flag to set to request exclusive write access in PHP it looks like. The video can be separate from the controller infrastructure though, and can easily be prefabbed webcam software, so he doesn't need to know what's going on there to write a controller.

Maniaman
Mar 3, 2006
I figured it would be easier to keep the video separate from the control. I'd like to avoid having to learn and use flash/java if at all possible.

You've given me quite a bit of information on what direction to take with it though, so I have some work to do while I'm waiting on hardware to show up.

Bob Morales
Aug 18, 2006


Just wear the fucking mask, Bob

I don't care how many people I probably infected with COVID-19 while refusing to wear a mask, my comfort is far more important than the health and safety of everyone around me!

What would be a good way to represent the 7 days of a week? In an options screen you would have a checkbox for each day, and then your program would use those selections to decide whether or not to perform some action on that day of the week.

So if you only checked monday-friday, it woudn't send you an email on Saturday or Sunday.

The first thing that comes to mind is a bitfield, and you could use a single byte to store the setting for each day. But that seems like that's not the best way to do it. This would be something that would get stored in a SQL database of some sort.

gariig
Dec 31, 2004
Beaten into submission by my fiance
Pillbug

Bob Morales posted:

What would be a good way to represent the 7 days of a week? In an options screen you would have a checkbox for each day, and then your program would use those selections to decide whether or not to perform some action on that day of the week.

So if you only checked monday-friday, it woudn't send you an email on Saturday or Sunday.

The first thing that comes to mind is a bitfield, and you could use a single byte to store the setting for each day. But that seems like that's not the best way to do it. This would be something that would get stored in a SQL database of some sort.

I would tackle it one of two ways. The first solution would have one table with bit fields for Monday, Tuesday, Wednesday, etc plus a foreign key back to your users. This would be the option I'd pick if you are pretty sure you are stick to the days of the week and the front end is hard coded to the days of the week plus your data set is staying small.

If you are going to expand this to have different triggers like quarterly, yearly, monthly, etc plus have the selection built dynamically on the front end I'd go with two tables. One table would store the selections so a field for the name of the selection and some sort of primary key. Then another table that tied a user to the triggered selection as a many-to-many relationship.

Between the two the second one would be the "better" of the two because you could easily put an index on the many-to-many table on user PK and trigger PK. The first option would require table scans or lots of indexes to have good execution plans but if your number of users is small then index coverage won't really matter.

Kire
Aug 25, 2006
C++ question about classes and pointer data fields.

I'm totally stuck on this part of a homework: I have a Student class, in which Student objects can be created. I want to create a pointer data field named bestFriend. This should point to another student. This should default to
null. There should be mutator and accessor functions for this variable. When the mutator is called it should set the bestFriend of both students (to each other). If one of the students already has a bestFriend, the caller object should set its bestFriend to null and print a warning.

The function I'm using right now is:
(in header file:)
code:
public:
void setBestFriend(Student, Student);
(in .cpp file:)
code:
void Student::setBestFriend(Student s1, Student s2)
{
  *(s1.bestFriend) = s2; 
  *(s2.bestFriend) = s1;
}
It seems to work ok as long as I don't try to cout << the result of it. Something goes terribly wrong with trying to display it with cout using the getBestFriend() accessor.
code:
Student Student::getBestFriend() //Pointer accessor function
{
  return *bestFriend;
}
It tells me "there is no operator "<<" which takes type Student as the right hand argument".

Suspicious Dish
Sep 24, 2011

2020 is the year of linux on the desktop, bro
Fun Shoe
Well, there's several problems here. First of all, you don't seem to be using pointer data fields correctly, instead setting the things that the fields point to by value, which is very likely what you don't want.

Make setBestFriend take one thing, a Student *, since it's not a static method. getBestFriend should return a Student * as well. As for printing, what do you want to do? It's saying "I don't know how to print a student!", and since you haven't given any more information, that's a fair thing for it to do. Define a method to cast it into something that an iostream can take, like a char * or a std::string.

Kire
Aug 25, 2006

Suspicious Dish posted:

Well, there's several problems here. First of all, you don't seem to be using pointer data fields correctly, instead setting the things that the fields point to by value, which is very likely what you don't want.

Make setBestFriend take one thing, a Student *, since it's not a static method. getBestFriend should return a Student * as well. As for printing, what do you want to do? It's saying "I don't know how to print a student!", and since you haven't given any more information, that's a fair thing for it to do. Define a method to cast it into something that an iostream can take, like a char * or a std::string.

How can it take only one arg? I need at least two Student types passed into it so they can be set to each other's bestFriend, right?

pseudorandom name
May 6, 2007

Right now, a third Student is in charge of who s1 and s2 are friends with, and that doesn't make any sense.

Suspicious Dish
Sep 24, 2011

2020 is the year of linux on the desktop, bro
Fun Shoe

Kire posted:

How can it take only one arg? I need at least two Student types passed into it so they can be set to each other's bestFriend, right?

A method is something that belongs to an object. In C++, that object is referenced in the body with a special keyword, this.

Kire
Aug 25, 2006

pseudorandom name posted:

Right now, a third Student is in charge of who s1 and s2 are friends with, and that doesn't make any sense.

What third Student? I'm confused. Should it be like this:
code:
void Student::setBestFriend(Student *)
{
  this->bestFriend = Student *Student;
}
Edit: Now I think I understand the third student issue- since the function can only be invoked by typing myStudent.setBestFriend(otherStudent) that already includes 2 objects, so I didn't need to send two objects as arguments.

Kire fucked around with this message at 20:45 on Mar 25, 2012

Suspicious Dish
Sep 24, 2011

2020 is the year of linux on the desktop, bro
Fun Shoe

Kire posted:

What third Student? I'm confused. Should it be like this:
code:
void Student::setBestFriend(Student *)
{
  this->bestFriend = Student *Student;
}

I forget if "this" is considered a pointer or a reference, but try:

code:
void Student::setBestFriend(Student *friend)
{
  this->bestFriend = friend;
  friend->bestFriend = this;
}

Kire
Aug 25, 2006

Suspicious Dish posted:

I forget if "this" is considered a pointer or a reference, but try:

code:
void Student::setBestFriend(Student *friend)
{
  this->bestFriend = friend;
  friend->bestFriend = this;
}

That compiled ok, but now I'm having trouble calling it:

code:
void Student::setBestFriend(Student *sfriend)
{
this->bestFriend = sfriend;
sfriend->bestFriend = this;
}
and in the main() function:
code:
Emily.setBestFriend(Shawn);
gives an error that it cannot convert the parameter from 'Student' to 'Student *'.

Suspicious Dish
Sep 24, 2011

2020 is the year of linux on the desktop, bro
Fun Shoe
Right, so I assume you're doing something like:

code:
int main() {
    Student Emily("Emily");
    Student Shawn("Shawn");

    Emily.setBestFriend(Shawn);
    return 0;
}
You need to make that into a pointer. If you're sure that you want to allocate on the stack, just use the reference operator:

code:
    Emily.setBestFriend(&Shawn);
Allocating on the heap requires use of the "new" operator, and is more complicated. I'd suggest you look at your course notes to see if you've covered the "new" operator, or talk to your professor or TA.

Johnny Cache Hit
Oct 17, 2011

Bob Morales posted:

What would be a good way to represent the 7 days of a week? In an options screen you would have a checkbox for each day, and then your program would use those selections to decide whether or not to perform some action on that day of the week.

So if you only checked monday-friday, it woudn't send you an email on Saturday or Sunday.

The first thing that comes to mind is a bitfield, and you could use a single byte to store the setting for each day. But that seems like that's not the best way to do it. This would be something that would get stored in a SQL database of some sort.

Congrats, you have just started writing a scheduler. I had to do this as a junior programmer. I didn't think much of it. But if I had to do this today, I would start getting really nervous, because I know that once I implement that management will be wanting:

  • office hours
  • ... which means timezones
  • ... and holidays
  • company-wide work weeks
  • ... which means custom work weeks/vacation time
  • :smithicide:

I'd do it like garlig says - M2M the user <-> some notification time. And get ready for some fun down the road.

baquerd
Jul 2, 2007

by FactsAreUseless
Do not write a scheduler. If you must, write a front end to an existing scheduler such as Quartz or even crontab.

raminasi
Jan 25, 2005

a last drink with no ice
You'll probably have more luck with the C++ question in the C++ thread.

The Atomic Man-Boy
Jul 23, 2007

I have a general logic question. I’m building an application (Java if you must know) that reads a user’s facebook information.

Once you log in, it retrieves a lot of information. But what I’m concerned about is that I can pull my ‘friends’ list and all my friends’ ‘mutual friends’ info. But after that, I would like to display a sort of "friends grid" in 2-d space.

I already can place their info on the grid, and show connections between them using lines.

The logic part is I would like to group them, and if they are common friends, put them closer together, while if they have no relationship with each other, I can keep them at a distance.

Take, for example, four groups(although I have no idea how many groups there will actually be in any given list):

Work: Wendy, Wally, Wesley, Wonda, and Wilma

Family: Fred, Francis, Francesca, and Frank

High school friends: Heather, Henry, Hal, Howard, Hermione, and Hector

College friends: Chris, Courtney, Carl, and Calvin

Misc friends: Mickey and Michelle.

Each group may have a strong relation, but not everyone is a friend with everyone else in a group.

Keep in mind that there are no facebook groups “my family” or “my high school friends,” because no one actually makes groups like that. My app should be able to figure out the grouping on its own(using only my friends ‘mutual friends’ data), even though there is sometimes some interlap. The final output should look something like this: (Blue lines represent a friendship) Notice that individuals are placed near common friends.



Thanks in advance to any goons who can give me some tips or point me in the right direction.

Lysidas
Jul 26, 2002

John Diefenbaker is a madman who thinks he's John Diefenbaker.
Pillbug
The term you're missing is "friends graph". The problem of identifying dense subgraphs is well-studied; I'd recommend looking at some of those papers and algorithms. You might also be able to use a graph clustering algorithm like MCL or a spectral method. Once you identify clusters or dense subgraphs, it should be pretty straightforward to adjust the positions of your nodes.

(I miss when Facebook actually let you visualize your friends network by passing it through something like graphviz; I think this was removed in 2005 or 2006 when it began to be too computationally intensive.)

EDIT: Wasn't thinking very clearly; as far as I know a spectral clustering method will give you a nice embedding of nodes in 2D space but you'll still have to use something like a graph cut method to get the clusters themselves, and you're very likely to hit the classic problem of "how many clusters do I want?"

Lysidas fucked around with this message at 14:27 on Mar 27, 2012

JawnV6
Jul 4, 2004

So hot ...
Check out the Girvan-Newman algorithm.

Doesn't help you with the "how many clusters" problem Lysidas mentioned, but it'll give you the clusters.

Lysidas
Jul 26, 2002

John Diefenbaker is a madman who thinks he's John Diefenbaker.
Pillbug
:love: Mark Newman. He does some amazing work with networks, and I was lucky enough to attend a talk he gave at my university last year.

Come to think of it, is a nice embedding in 2D space all you need? I suspect that I was making the problem more complicated than it is.

Opinion Haver
Apr 9, 2007

You could also look at the graphviz library if you're only interested in drawing graphs and don't particularly want to compute the clusters.

Crankit
Feb 7, 2011

HE WATCHES
I think I want to mess with an app's API calls on windows, but I don't yet know how.
I have an app that grabs files which are linked from an RSS (podcast), however the files require a password in the url (http://user:pass style), this app asks for username and password every time.

I was going to set the app up to use a proxy but it uses the windows settings for proxies which means all my apps would end up going through a proxy and having an app run on startup etc. What I think I want to do is make a stub dll that pass on all function calls to the original but changes the url for downloads from a certain server.

Having typed all this, it looks like a silly plan, on the basis that my computer is pretty slow etc so I don't want to be running a proxy server all the time, what would you guys suggest?

The Gripper
Sep 14, 2004
i am winner

Crankit posted:

I think I want to mess with an app's API calls on windows, but I don't yet know how.
I have an app that grabs files which are linked from an RSS (podcast), however the files require a password in the url (http://user:pass style), this app asks for username and password every time.

I was going to set the app up to use a proxy but it uses the windows settings for proxies which means all my apps would end up going through a proxy and having an app run on startup etc. What I think I want to do is make a stub dll that pass on all function calls to the original but changes the url for downloads from a certain server.

Having typed all this, it looks like a silly plan, on the basis that my computer is pretty slow etc so I don't want to be running a proxy server all the time, what would you guys suggest?
You might be able to just run a lightweight proxy server on localhost:80 and put an entry for sub.whateverurl.com localhost in your hosts file. That way only traffic to that destination will be proxied (but doesn't help if you don't want a full-time proxy running).

Since it would only be proxying specific traffic outright it wouldn't put a significant amount of load on your system.

Edit; I don't know if doing it this way will bust up the proxy though, since it's possible requests to sub.whateverurl.com/whatever&x=y will be changed to requests to localhost/whatever&x=y (which the proxy wouldn't handle).

The Gripper fucked around with this message at 05:20 on Mar 28, 2012

The Atomic Man-Boy
Jul 23, 2007

Yes, all i need is an embedding in 2-D space. Because the only info I have is the 'mutual friends' that is the basis for the edge in any given graph. Most friends will fall neatly within any given cluster. ie work friends, high school friends, friends from my old job, friends I met during study abroad etc. The job is now to roughly identify some clusters, show it in 2-d space, and roughly build it around that.

I realized that my with the information my program fetches, it cant identify the difference between "my work friends" and "that one guy who got invited to the office party once, but he was pretty funny so no he's facebook friends with everyone else at work." He'll probably get thrown into the cluster anyways, which is fine.

But I'd still like it to figure out if which cluster a person belongs to if they branch out into multiple clusters.

Adbot
ADBOT LOVES YOU

Nippashish
Nov 2, 2005

Let me see you dance!

The Atomic Man-Boy posted:

Yes, all i need is an embedding in 2-D space.

...

But I'd still like it to figure out if which cluster a person belongs to if they branch out into multiple clusters.

So which is it? :raise: Do you just want to embed the graph in 2D space or do you want to assign each node to a cluster?

Also I'm going to suggest laplacian eigenmaps for the embedding, because it's really easy to implement (as long as you have access to an SVD routine).

  • 1
  • 2
  • 3
  • 4
  • 5
  • Post
  • Reply