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
Jose Cuervo
Aug 25, 2004

csammis posted:

But along those lines: Wherever you're adding an entry to the dictionary, how about you just add a check to see if the key that's being added satisfies the property you want, and save it?

I think I am going to go with this method. On a related note, (although this is VB specific), if I wanted an array or a dictionary to be accessible by any function in any part of my code (even if it is in a different class), what would I need to put in my main to do that?

I would prefer the array/dictionary to be read only, but this is not crucial.

Adbot
ADBOT LOVES YOU

Jose Cuervo
Aug 25, 2004
I am trying to generate a bunch of combinations(?) as follows:
I have three groups:
GROUP 1: 2 3 4
GROUP 2: 5 6
GROUP 3: 0 1

The twelve combinations I generate are found by picking one memeber from each group and are:
250
251
260
261
350
351
360
361
450
451
460
461

I generated them using the following MATLAB code:
code:
for i=[2,3,4]
    for j=[5,6]
        for k=[0,1]
            fprintf('%s%s%s\n',num2str(i),num2str(j),num2str(k))
        end
    end
end
My problem is that in general I do not know how many groups I will have. For each new group I need an additional for loop. Is there a way to generalize the code so that it works for an arbitrary number of groups?

Jose Cuervo
Aug 25, 2004
I have a bunch of pdf files that I want to put online for someone to be able to access, but I do not want to have to manually type in the names of all the files as:

<a href="filename.pdf">Filename</a>

since the names of the files are pretty long and involved and there are 45 or so of them.
The way I was thinking of doing this is to write some sort of script(?) that will look in a particular folder and generate a text file that has an entry like the one above for each pdf file in the folder. Then all I have to do is copy that information and paste it in my .html file.

Is this even feasible? And if so, where can I look to get some basic info on how to accomplish this?

Jose Cuervo
Aug 25, 2004

Avenging Dentist posted:

Why not just upload them all to a directory and allow the directory itself to be viewed?

That would be the easiest way, but I do not know how to do this. I am using the personal webpage given to me by my university. If you could point me in the right direction I would appreciate it.

Jose Cuervo
Aug 25, 2004

Thanks for the link. Although I was not able to get it to work I did manage to write a script to accomplish what I need.

Jose Cuervo
Aug 25, 2004
I have the following problem, and I do not know how to logically approach it:
I have N different time intervals of the form [a,b] (e.g. the time interval [5,9] consists of the times 5, 6, 7, 8, and 9). The problem is to determine the intersection of these N time intervals, where some will overlap, and some will not.
For example, if I have [19,23], [3,7], [5,19], and [44,48], the resulting intersection I want is [3,23], [44,48].

Right now I am able to take all the start and end points of each time interval and sort them in ascending order [3, 5, 7, 19, 19, 23, 44, 48] and have an accompanying vector [s, s, e, s, e, e, s, e] of which point is a start or end.

I am lost as to how to use this information to come up with the resulting intersection, and I am open to new strategies. Any ideas?

Jose Cuervo
Aug 25, 2004

shrughes posted:

You're talking about the union.


You're real close. Now you need to walk through the s/e array, left to right, and keep "score", where the score is the number of opening braces minus the number of closing braces. The score starts at zero. Whenever the score increases from zero to one, "output" an open brace and the number at the current index. Whenever the score decreases from one to zero, "output" the number at the current index and a closing brace. Then clump adjacent intervals that end and then start on the same number, like you have with 19. That's more work than necessary

An alternate implementation: Sort by the lower bound, and then pop two intervals and push one interval, occasionally outputting when you have a complete interval.

code:
unionIntervals :: [(Int, Int)] -> [(Int, Int)]
unionIntervals [] = []
unionIntervals xs = go (sortBy (compare `on` fst) xs)
    where go :: [(Int, Int)] -> [(Int, Int)]
          go [x] = [x]
          go ((x1,x2):(y1,y2):xs)
              | x2 < y1   = (x1,x2) : go ((y1,y2):xs)
              | otherwise = go ((x1, max x2 y2):xs)

Doh! Of course I meant union. I do not understand the code you wrote, but I will try and implement the 'score' keepeing procedure you outlined, and see how I fare.

EDIT:
I am working in C++, and I implemented what I think you meant. It seems to work for the examples I have tried on it, but I am at a loss to explain why this method of keeping score works. DO you have any explanation, or a link to an explanation of why this works?

Jose Cuervo fucked around with this message at 05:59 on Apr 27, 2010

Jose Cuervo
Aug 25, 2004

shrughes posted:

Imagine yourself walking along the number line, from left to right. Every time you enter one of the intervals, you add 1. Every time you leave one, you subtract 1. Scaevolus is gay.

The score tells how many overlapping intervals you're in. So as long as it's nonzero, you're inside one of the intervals.

Gotcha. Thanks so much.

Jose Cuervo
Aug 25, 2004
I have written a small program in C++ using Microsoft Visual Studio. The inputs to the program are 4 different integers (number of machines, number of machine groups, number of workers, number of jobs). I want to run the program with 2000 different combinations of these inputs on another computer that does not have Visual Studio. I have heard that I can compile my program into an exe file (?), and then pass each combination of inputs to it using a batch file, but I cannot find any help as to how to do this.

Can anyone give me some help/advice on how to do this, or point me to some resources that would help me with this issue?

Jose Cuervo
Aug 25, 2004
I am writing a program in Visual Studio (C++) (this is my first time really using pointers) and I finally have it at the point where I am running big problems on it. Running big problems slows my system way down - my music player halts while the program is running, etc.
From looking at Windows Task Manager, it seems like at some points up to 1,500,000K in the Memory (Private Working Set) is being used by my program. Is this an accurate measure of the amount of memory (RAM) my program is using? And is this an indication that I have memory leaks due to the fact that I have not deleted all pointers I created? I went back and made sure to add delete statements after I was done with any pointer I have created, but this continues to be a problem. Ideas?

Jose Cuervo
Aug 25, 2004

PDP-1 posted:

Maybe, maybe not. Have you tried estimating how much memory your Big Problem should be using?

For example if you have an object that is about ~1kb in size and you make an array of 10 of them, finding out that your program is taking up a gigabyte of memory indicates a problem. If you take the same 1kb object and make a 1024x1024 2D array then using a gig of memory is just the natural consequence of storing that much data.

My code has two parts - part one develops a lower bound for a schedule using a network flow approach, and part two is a schedule builder. If I run the program without using the lower bound computation, the maximum memory used by the program is 60,000K. If I use the lower bound computation, then the program takes 1,500,000K.
The network flow computation requires me to have 7 different long int arrays. For the problem I am running, on average they are of size 1x10,000. The network flow code is called 17 times for the problem, and the memory being used increases by 80,000K-120,000K each time the network flow code is called (which is how the program ends up using 1,500,000K total). But I am calling the delete function on all 7 arrays each time I am done with a call to the network flow code, so in my mind the amount of memory I am using should be 60,000K+120,000K at the very maximum, and should fluctuate between 180,000K if the network flow code has been called and the arrays are being used, and 60,000K if the network flow code has deleted the arrays.
Is this not correct thinking?

Let me know if you need more information.

Jose Cuervo
Aug 25, 2004

Mustach posted:

Are you calling delete or delete []

I call delete if I have a pointer declared as
code:
int *myIntPtr= new int;
and I call delete [] if I have a pointer declared as
code:
int* *myIntArrayPtr= new int*[numMachines];
So in my code, I have:
code:
int *myIntPtr= new int;

*myIntPtr= 77;

delete myIntPtr;
and
code:
int numMachines= 10;

long int *myIntArrayPtr= new long int[numMachines];
long int* *myIntArrayPtr2= new long int*[numMachines];

for (int i=0; i<numMachines; i++)
{
   myIntArrayPtr[i]= i;
   myIntArrayPtr2[i]= new long int[numMachines];

   for (int j=0; j<numMachines; j++)
   {
      myIntArrayPtr2[i][j]= j;
   }
}

//Delete the arrays

delete [] myIntArrayPtr;

for (int i=0; i<numMachines; i++)
{
   delete [] myIntArrayPtr2[i];
}

delete [] myIntArrayPtr2;
Is my usage of the delete function not correct?

Jose Cuervo
Aug 25, 2004
I have a program that creates graphs which runs from the command line. The command
code:
gle -d pdf -o graph1 graphCode.gle arg1 arg2
creates graph1.pdf where arg1 and arg2 are two arguments unique to graph1.pdf. I have to create 30 graphs with differing arg1 and arg2 values, and I was wondering if there was a way for me to write a file with each line containing a command with the arg1 and arg2 values as appropriate, such that when I run that single file, it executes all the commands and creates all the graphs automatically.

Is there a way to do this?

I am using Win7 if that makes a difference.

Jose Cuervo
Aug 25, 2004
The batch files idea worked perfectly. I now just have to double click the batch file and I have 30 different graphs 10 seconds later. Thank you.

Jose Cuervo
Aug 25, 2004
Mistakenly posted this. Sorry.

Jose Cuervo
Aug 25, 2004
I have the following problem. Each night I want to create a backup of a project I am working on. The way I do it now is, I use WinSCP to access the J drive (remote drive) my university gives me, and then copy over the latest version of the 6 files that make up my project to a folder on my J drive. I was wondering if there was any way to automate that process - i.e., could I potentially write a script(?) that, when run, would automatically log into WinSCP and then copy over the 6 files to the specified folder?

Really I am looking for some pointers as to what tools can be used to accomplish the task, and I will go read up and try to figure it out.

Jose Cuervo
Aug 25, 2004

TasteMyHouse posted:

this should be pretty trivial! there are a million different ways to do this, but since you're already familiar with WinSCP...

Doh! Did not even think of looking at their website. Thank you.

Jose Cuervo
Aug 25, 2004
I am in an Industrial Engineering program, but as part of my research I came up with a piece of code that takes a set of jobs and a set of machines and then uses some scheduling logic to build an actual schedule. I have now been asked to look at the time complexity of the code - from looking this up online it seems that I need to determine how long the code would take to run if it had an input that was 'n' units big. I am not sure how to start doing this, and was wondering if anyone had any pointers as to how I would go about figuring out the time complexity. For example, do I write the code as pseudocode first and then estimate the number of operations each line takes, or ...? And what defines an operation?

Jose Cuervo
Aug 25, 2004
I am not sure if I can achieve what I want, so hopefully you all will be able to tell me if what I want to do is impossible.

I have 4 different papers that I am writing that are each located in a separate folder. Each paper has it's own local plain text bib file with the citation information of the citations needed for that paper. The citation information is stored in the BibTeX format. A number of the citations overlap - i.e., the citation is used in more than one paper.

The two questions are:
1. Is it possible to write some code/script so that I would have one master plain text bib file with all the citations, and whenever I made a change to a citation, I could run the code/script so that the citation information gets updated in each local paper's plain text bib file?

2. Can someone with limited coding ability (me) write this code given a plan of how to do it?

I have been doing the updating manually, but sometimes I do not update everything, or I misspell something and it is getting to be very aggravating.

Jose Cuervo
Aug 25, 2004

ToxicFrog posted:

This is possible, and given the simplicity of the BibTeX format, not even very hard, but it also sounds a lot like overkill compared to the other possibilities:

- merge all of the BibTeX files, have all four papers reference the same .bib directly rather than having its own copy of a subset of it
- have a single "common" BibTeX file that contains all of the citations used in more than one paper, and a file of paper-specific citations for each paper; have each paper reference both the common.bib and the paperspecific.bib.

Of those, I think I'd prefer the first one.

The issue with the first solution (which is how I was doing things to start) is that I have co-authors and need to upload the files to a single folder that they can then use to compile the latex files. Unless I force them to use the same relative file structure as I do, and have them download the master bib file each time this option does not work.

Hammerite posted:

Yes, that is something that you could do reasonably straightforwardly with the scripting language of your choice. Do you have any experience using a scripting language like Python, Perl, Lua, etc etc.?

I do not know how others would approach this (and I do not know anything about bibtex), but here is what I might do, assuming you do not want to go to the trouble of involving a relational database:

- Make a master citations file with all of the citations in it, together with identifying names (for your use). You could do a citation on every line of the file, with name first then citation text separated by a tab. Or you could do it innumerable other ways.
- If your papers are spread across a number of directories, then make another file that lists all of the directories to be searched and updated.
- For each paper, make a file called something like "papername.mybib" that just has a list of the citations you want, identified by the name you used in the master citation file.
- Now write your script. The script should read from the two master files. From the first one it builds up a list of identifiers and the citation text for each one. From the second one it reads a list of directories to search through. It goes through each directory in turn looking for .mybib files. For each one, it generates a .bib file.

When reading the first master file, the script should be prepared to encounter blank lines and lines that are "comments" (say, lines starting with % or #), so that you can lay it out in a way that is pleasing and easy for you to read.

I don't know any of the scripting languages you mentioned, but with the sketch of how to accomplish this I think I can fumble my way through. Thanks for the insight into how to attack this problem.

Lysidas posted:

You could concatenate all of the .bib files together, symlink the single .bib file into each paper's directory, and fix the 'duplicate citation' errors/warnings if and when they happen.

Not quite sure what this means, but I think I will go with the Hammerite's solution.

Jose Cuervo
Aug 25, 2004

ToxicFrog posted:

How does splitting it into multiple files (that they still need to re-download each time they change) address this?

When I have a separate *.bib file for each paper, the *.bib file is contained in the same folder that contains the *.tex files for the paper. When I send them the latest version of the paper, all the necessary files are zipped in one folder so that all they need to do is extract the files to a single folder and can go from there. With the master bib file idea, they would then need to put the master bib file in the appropriate (relative) folder, which is one step to many for my advisors.

ToxicFrog posted:

Hammerite's solution may be overkill, honestly. BibTeX is a pretty simple format and you don't really need (or want) a separate, non-BibTeX master file that gets processed into BibTeX. Revised version:

pre:
- read master.bib file
- foreach paper:
  - read the paper-specific ".mybib" file, which is just a list of papers you
    want to cite (using the same names they're listed under in the master.bib)
  - foreach paper listed: copy that entry from the master.bib into a paper-
    specific .bib file
I could probably hack together a simplified example implementation in Clojure or Lua if you want one.

I know what I want is probably overkill, but I would like to make certain that each time I make a change to a citation, that exact change occurs everywhere. If you wouldn't mind putting together the example implementation I would appreciate it.

Jose Cuervo
Aug 25, 2004

ToxicFrog posted:

In that case the symlink idea will work perfectly. Merge all of the files, create a symlink in each paper's folder to the master file. When you zip the folder, the zip file will contain the master file the symlink pointed to when you zipped it, so anyone unzipping it will have the right file in the right place, no fuss.

As an added bonus, this way you don't need to re-run the script every time you modify the master file!


Sure thing.

E: here it is. I offer this mostly as a programming exercise; I still think the symlink approach is better.

Note that as an example, error checking is minimal; if it can't open a file it'll just abort, and if a file already exists that it wants to write it'll be overwritten.

Thanks for this. I am going to look at the example and read up on the symlink stuff.

Jose Cuervo
Aug 25, 2004
Although it is overkill, I managed to code up a script(?) in python based on the help provided here. Thanks for the guidance.

Jose Cuervo
Aug 25, 2004
I am trying to find a better way to do the following because the solution I use is impractical when the number of groups (numGroups) gets large. I have a target number of workers (targetWorkerNumber) that I want, and I have numGroups number of groups where I can place workers. I also know the minimum and maximum number of workers I can place in each group (if it helps the maximum number of workers for each groups is the same, but the minimum number of workers can differ based on the group in question). I want to determine all possible permutations of workers that add up to targetWorkerNumber but also respect the minimum and maximum worker restrictions of each group.

The code I am using now is given below. It begins with allocating the maximum number of workers to each group, and then performs a check to see if the number of workers in that permutation adds up to targetWorkerNumber. If not, it decrements the number of workers in the last group, and performs the check on the new permutation. However if the number of workers in the last group is decremented below the minimum number of workers for that group the number of workers in that group is reset to the maximum number of workers, and the number of workers in the next to last group is decremented, and so forth.

Unfortunately I have found out that this is a horribly inefficient way of doing things. I now have 20 groups and each has a maximum of 8 workers, and this brings everything to a standstill. Any ideas on how I can improve the code/ an alternate way to do things?

C++ code:
while (true) {
	for (int j=numGroups; j>1; j--) {
		if (workersInGrp[j] == minWorkers[j]-1) {
			workersInGrp[j]= maxWorkers[j];
			workersInGrp[j-1]--;
		}
		else
			break;
	}

	int totalWorkers= 0;
	for (int k=1; k<=NumMachineGroups; k++)
		workersInTrialAlloc += workersInGrp[k];

        if (workers == targetWorkerNumber) {
                // do stuff
		break;
        }
        workersInGrp[numGroups]--;
}

Jose Cuervo
Aug 25, 2004

HappyHippo posted:

Do you need to do something for each permutation, or do you just need one that works? Because your code makes it look like you just need one (with the break; statement after the //do stuff). The number of permutations can get impractically large quite quickly, so doing something for each one might just not be possible no matter how efficiently you find them.

Sorry I do need all of them, not just the one. The Gripper I will take a look at your code tomorrow morning, thank you for the help. Time for bed.

Jose Cuervo
Aug 25, 2004

HappyHippo posted:

OK, so just to give you some perspective:

Say you have 20 groups, with 8 max and 5 min for each, and you wanted to put 120 people into them (so about 6 on average). If I've done my math right that's about 12 billion possible permutations. If that was instead 8 max/2 min you'd have about 226 trillion possible permutations.

DOH! Should have thought about the numbers involved. I guess anything I come up with will end up taking a very long time. Thanks for the help.

Jose Cuervo
Aug 25, 2004
I have what is similar to a knapsack problem, but with a twist:

I have a list of volumes of different (non-mixable) liquids each with a priority score (lower denotes the liquid is more important), and a list of containers.

For example the list of liquids and priorities is [(30gal, 1), (27gal, 2), (40gal, 1.5), (15gal, 3)] and the list of containers is [5gal, 5gal, 8gal, 10gal, 10gal, 10gal]. In this example there is not enough volume in the containers to accommodate all of the liquid.

I want to determine how to assign the liquids to containers to maximize the weighted amount of volume carried. I cannot mix the liquids but it is okay to not take the full volume of one liquid and it is okay to not fully fill up a container.

Does this sound like a problem that already has a solution I can use?

Jose Cuervo
Aug 25, 2004

ultrafilter posted:

What's the exact objective function that you're trying to maximize? It's not obvious how the priority scores should be interpreted. If I have [(1, 1), (100, 2)] and a single 100 gallon container, I need to know whether it's better to take the one gallon of the high priority liquid or the 100 gallons of the low priority liquid.

Edit: Don't just tell me the answer to this particular instance. The important question here is in my first sentence.

This is a good question, and not something I had completely defined yet. To be honest I need to define the 'priority score' precisely as well before I can define the exact objective function. I will have to think carefully about it and get back to you. Thanks for the initial help/ pointers.

Jose Cuervo
Aug 25, 2004
I have a small program I am writing that contains custom objects in it. For example I have a container object that has a name, maximum amount of liquid it can hold, types of liquid it can hold, cost of holding each type of liquid, and the current amount and type of liquid being held.

I want to store this information (not hard code it into the program), and was wondering if there are any best practices for how to do this.

Would I be best of using a text file and writing all the data in a specific format that I can then read in, or is there something better?

Jose Cuervo
Aug 25, 2004

Bunny Cuddlin posted:

It depends on the language you're writing in. Some of them have built in facilities for storing and reading a configuration file. For instance, python has ConfigParser. The .NET way is generally to use an XML file. A json file would work too. Use something you can easily parse with features built into your language's standard library is my advice.

Sorry I should have specified that Python is what I am using. I will look into ConfigParser.

Jose Cuervo
Aug 25, 2004
I have an idea for a programming project (hopefully in Python) but I am not sure on how to get started. I was hoping to get some ideas on how to accomplish the following:

Given a Google maps route (road trip), I would like to produce a list of the counties that the chosen route passes through.

I think that what I need to have is a list of all the US counties and the coordinates that define each county. Then somehow iterate over the route (say 500 feet at a time) and keep checking what county that part of the road is in. However I don't know how I would be able to accomplish this. Any thoughts/ pointers?

Jose Cuervo
Aug 25, 2004
I am trying to modify a bash script that looks like this:
Bash code:
param_file="../unrolledParamFile.txt" # unrolled param file
instanceDir="instance_1"
instance=1

#--------------------------
begin=1
end=1
echo "Running lines $begin to $end"
inputArg=`sed -n "$begin","$end"p "$param_file"`
echo $inputArg
cd $instanceDir

~/pd/java7/jre1.7.0/bin/java -Xmx1024m -cp "../lib/*" repast.simphony.batch.InstanceRunner \
	../scenario.rs/batch_params.xml ../scenario.rs "$inputArg" $instance
#--------------------------
If param_file only has one line in it, this works fine. However I want to have param_file contains multiple lines, and place the code in between the comment lines in a for loop so that the program gets called for each set of parameter combinations contained on each line.

I am having trouble understanding what the line
Bash code:
inputArg=`sed -n "$begin","$end"p "$param_file"`
does, and how to generalize this to a loop that iterates over each line in param_file.

EDIT: Figured this out. Posting here in case anyone wants to know:
Bash code:
param_file="./unrolledParamFile.txt" # unrolled param file

instanceDir="instance_1"
instance=1
while read line
do	
	inputArg=$line
	echo $inputArg
	cd $instanceDir

	~/pd/java7/jre1.7.0/bin/java -Xmx1024m -cp "../lib/*" repast.simphony.batch.InstanceRunner \
		../scenario.rs/batch_params.xml ../scenario.rs "$inputArg" $instance
done < "$param_file"

Jose Cuervo fucked around with this message at 16:10 on Aug 14, 2014

Jose Cuervo
Aug 25, 2004

Jose Cuervo posted:

EDIT: Figured this out. Posting here in case anyone wants to know:
Bash code:
param_file="./unrolledParamFile.txt" # unrolled param file

instanceDir="instance_1"
instance=1
while read line
do	
	inputArg=$line
	echo $inputArg
	cd $instanceDir

	~/pd/java7/jre1.7.0/bin/java -Xmx1024m -cp "../lib/*" repast.simphony.batch.InstanceRunner \
		../scenario.rs/batch_params.xml ../scenario.rs "$inputArg" $instance
done < "$param_file"

Another question. Right now if there are 10 lines in the param_file, ten processes will be started almost simultaneously. Is there a way to say that I want the first line to be done running before I begin the second line?

Jose Cuervo
Aug 25, 2004
Working in Python, but I think this is more of a general question. I have 2 lists of intervals (where an interval is a start and an end point and both the start and end points are inclusive). What I want is a single list of intervals that is the union of the two lists, but which identifies where the intervals overlap. For example if:
Python code:
list1 = [[1, 5], [6, 7], [19, 21]]
list2 = [[4, 6], [8, 19.5]]
then the resultant list should be:
Python code:
new_list= [[1, 4, 1], [4, 5, 2], [5, 6, 1], [6, 7, 1], [8, 19, 1], [19, 19.5, 2], [19.5, 21, 1]]
where the third number illustrates how many intervals "covered" that part of the real line.

Any ideas on how to do this (or if there is existing code that does this) would be welcome.

Jose Cuervo fucked around with this message at 22:41 on Mar 10, 2015

Jose Cuervo
Aug 25, 2004
This question concerns implementing Common Random Numbers in a simulation model (coded in Python, but I think the question is language agnostic).

The simulation is a small supply chain which has 4 factories producing goods and where I would like to be able to compare inventory policies. The amount of raw material used each day at each factory is a random variable (so 4 numbers drawn from the random number stream). The inventory policy at each factory determines when new raw material will be ordered so that the factory does not run out of raw materials, and the time it takes the raw material to arrive at the factory is a random variable (a single number drawn from the random number stream).

In order to implement common random numbers I need to make sure that the amount of raw material used at each factory each day is the same regardless of the policy being used, however I cannot think of a way to ensure this happens using a single random number stream: under different policies the random number used as the time it takes a reorder to arrive at the factory can be a different random number in the random number stream. For example, if under policy_1 raw material is not reordered until day 6 at Factory 1, but under policy_2 it is reordered on day 4, and assuming that no other factories reorder, then under policy_1 the random number used as the time it takes a reorder to arrive is the twenty-fifth number in the random number stream, but under policy_2 it is the 17th.

Thus it appears I need five random number streams (one for the amount of raw material used, and one each for the amount of time it takes a reorder to arrive at the factory). Am I missing something?

Jose Cuervo
Aug 25, 2004

Jabor posted:

Using a unique random number stream for each factory's time-to-arrive doesn't seem anything like using common random numbers. Surely you just need two streams, one for each purpose the random numbers get used for?

What I am concerned with achieving is (from the Wikipedia link):
code:
... a specific random number used for a specific purpose in one configuration is used for exactly 
the same purpose in all other configurations. For example, in queueing theory, if we are comparing 
two different configurations of tellers in a bank, we would want the (random) time of arrival of the
Nth customer to be generated using the same draw from a random number stream for both configurations.
Suppose that under policy_1 the order of draws is: [1 2 1 3 2 3 2 3 1 4 2 4 3 2] while under policy_2 the order of draws is [1 2 1 4 3 3 2 3 1 4 2 4 3 2], where i={1, 2, 3, 4} represents the factory that the draw belongs to. If I used a single random number stream for all factories time-to-arrive, then under different policies the same draw is not necessarily used for both policies (for instance the first time-to-arrive for factory 4 is the 10th draw in the random number stream under policy_1 but is the 4th draw in the same random number stream under policy_2).

The only way I can think of to guarantee that the same time-to-arrive is used in both (or really in all) policies is to have a unique random number stream for each factory's time-to-arrive.

Jose Cuervo
Aug 25, 2004

Jabor posted:

Ah, sure.

What's your objection to having a different random number stream for each of these purposes?

Absolutely no objection. My next question is how to successfully implement this.

I need s = 5 unique random number streams for each simulation replication r. I also need to use the same s = 5 unique random number streams for the r-th simulation replication of the p-th policy.

In Python I could initialize a single random number stream using r (the index of the simulation replication). Then the first of the s unique random number streams would be initialized using the first s draws from that random number stream:
Python code:
import import numpy.random as npr

def int_seed(random_stream):
    """Use random_stream to compute an integer seed that is bounded
    above.
    @rtype : int
    """
    return random_stream.randint(10000000)


r = 101
rep_rand_strm = npr.RandomState().seed(r)

raw_mat_rand_strm = npr.RandomState(int_seed(rep_rand_strm))
fac1_rand_strm = npr.RandomState(int_seed(rep_rand_strm))
fac2_rand_strm = npr.RandomState(int_seed(rep_rand_strm))
fac3_rand_strm = npr.RandomState(int_seed(rep_rand_strm))
fac4_rand_strm = npr.RandomState(int_seed(rep_rand_strm))
In this way no matter what the policy is, I know that if r=101 I will have the same 5 unique random number streams, right?

Adbot
ADBOT LOVES YOU

Jose Cuervo
Aug 25, 2004
I know that I can use the Google Maps Directions API to return a json file containing the directions from point A to point B, including waypoints and alternative routes if so desired. Doing this requires formatting a string to the specifications provided (e.g.: https://maps.googleapis.com/maps/api/directions/json?origin=New+York,NY&destination=Orlando,FL), and then sending a request:

code:
import requests

r = requests.get('https://maps.googleapis.com/maps/api/directions/json?origin=New+York,NY&destination=Orlando,FL')
print r.json()
However, I was wondering if it was possible to set up a simple website that uses a Google Maps Embed API and then somehow take the route selected on the Maps Embed API and get the json for that route? This would allow me to select the precise route I wanted (for instance select a specific alternative route or reroute a small part of the trip by dragging the blue line). If it is possible, any pointers on what I should look into to do this would be appreciated.

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