How to solve a big number of problems automatically in AMPL? - ampl

i have a big number of problems (app 5000 instances) that i want to solve in ampl and i like to do it in one run in a for loop. I know how to reset the data and how to make a loop, but i don't know if you can make a name and then call the data from that name, like you can do in C with "printf" and then open the text with that.
I'm thinking if i can't change the name automatically in ampl, call ampl from C with "system()" and change the data file in C.
My question is if this is possible.

You can do it using AMPL script, for example:
for {i in 1..5000}
shell('ampl problem' & i & '.ampl');
This will run ampl on problem1.ampl, ... problem5000.ampl.
The shell command is similar to the system function in C and other languages. It is described in the AMPL book.

Related

How to execute if there's a certain block within a radius

I'm trying to figure out how to execute (for example /say hi) when there's Yellow Terracotta in a certain radius or field, however I can't figure out how to do it.
Anyone knows?
Using Minecraft 1.16,
"Execute" command has several syntax options. You can use the form "execute if block run "
Using the proper block name, we can get:
execute if block 1015 63 989 minecraft:yellow_glazed_terracotta run say hi
This targets a specific position.
I am a little less clear on how to achieve specifically what you are asking, but here are my thoughts:
The syntax provides for another form "execute if blocks..." This form allows you to select a range by corners, but it must be compared against a third selection of the exact same size (only the corner can be specified). I think the regions must be exactly the same, and may not allow for random placement of the block anywhere within the region.
Another way might be using different execute if commands instead to select an entity, and test where the entity is standing.
If you put a button on a command block and set it to:
execute at #p if block ~ ~-1 ~ minecraft:yellow_glazed_terracotta run say hi
When the player hits the button on the command block (obviously they must be within range of the button to press it) it shall check if the block -1 under the #p is "yellow_glazed_terracotta", and it will run say hi.
#p can be modified with [distance=..3] which means the player targeted by the command block must be within 3 blocks of the command block:
execute at #p[distance=..3] if block ~ ~-1 ~ minecraft:yellow_glazed_terracotta run say hi
So, this is sort of creating that range that you were looking for.
Some sources use "execute as #a at #s..." as a way to target any player when they step on a certain block anywhere at anytime. It may be possible to modify this into a distance as well, but it seems that the player will need to stand at a specific relative position to the terracotta.
If I find a better way to achieve this, I'll follow up.
The subreddit r/MinecraftCommands has a decent community that messes with Minecraft commands and command blocks. They may have further insight.
If I find a better way to achieve this, I'll follow up.
Edit- The only other thing I can think at this point is to take the first command I suggested and repeat it for every single coordinate in an area. If a terracotta block is any of those spaces, it will run the say hi command.
If you place all of these command lines into a function file you can call for the function when the command block is activated.

Octave: quadprog index issue?

I am trying to run several files of code for an assignment. I am trying to solve an optimization problem using the "quadprog" function from the "optim" package.
quadprog is supposed to solve the optimization problem in a certain format and takes inputs H,f, A,b, Aeq, Beq, lb, ub.
The issue I am having involves my f which is a column vector of constants. To clarify, f looks like c*[1,1,1,1,1,1] where c is a constant. Quadprog seems to run my code just fine for certain values of c, but gives me the error:
error: index (_,49): but object has size 2x2
error: called from
quadprog at line 351 column 32
for other values of c. So, for example, 1/3 works, but 1/2 doesn't. Does anyone have any experience with this?
Sorry for not providing a working example. My code runs over several files and I seem to only be having problems with a specific value set that is very big. Thanks!
You should try the qp native Octave function.
You mention f is: c*[1,1,1,1,1,1] but, if c is a scalar, that is not a column vector. It seems very odd that a scalar value might produce a dimensions error...

Getting KeyError when trying to create multiple variables in for loop ("post0", "post1", etc.)

Very new to python - just started actually using it yesterday. I'm running a for loop that scans a text file and copies specific parts of it into variables that will then be put into a class "post". I want to create a new post at the bottom of the loop, named "post0", "post1", and so on, corresponding with the number of times the for loop has been run. This is what I'm trying to use:
postname = globals()['post%s' % s]
And I currently am trying to have it print the name of the post every time it creates one with a simple print(postname). 's' is the variable the for loop runs off of, if that makes sense. It starts at 0 and runs up to the number of lines in the text file, currently 424.
When I run the code, it returns "KeyError: post0". What am I doing wrong?
Also, reading around here it seems that creating variables this way is bad practice. If there is a more efficient way to do it I'd be happy to try that instead, but I'd also like to know how to make this method work just so I understand the concept. Thanks.
Edit: Problem solved! See my answer below.
I created a list postlist = [] outside of the loop, then inside the loop I append the list with a "post_" where "_" is the 's' variable. Looks like this:
postlist.append('post%s' % s)
Python is cool!

Extracting information from a file variable in d3 pick basic

I have a file variable in d3 pick basic and I am trying to figure out what file it corresponds to.
I tried the obvious thing which was to say:
print f *suppose the file variable's name is f in this case
but that didn't work, because:
SELECTION: 58[B34] in program "FILEPRINTER", Line 7: File variable used
where string expression expected.
I also tried things like:
list f *didn't compile
execute list dict f *same error
execute list f *same error
but those also did not work.
In case any one is wondering, the reason I am trying to do this in the first place is that there is a global variable that is passed up and down in the code base I am working with, but I can't find where the global variable gets its value from.
That file pointer variable is called a "file descriptor". You can't get any information from it.
You can use the file-of-files to log Write events, and after a Write is performed by the code, check to see what file was updated. The details for doing this would be a bit cumbersome. You really should rely on the Value-Add Reseller or contract with competent assistance for this.
If this is not a live end-user system, you can also modify an item getting written with some very unique text like "WHAT!FILE!IS!THIS?". Then you can do a Search-System command to search the entire account (or system) to find that text. See docs for proper use of that command.
This is probably the best option... Inject the following:
IF #USER = "CRISZ" THEN ; * substitute your user ID
READU FOO FROM F,"BLAH" ELSE
DEBUG
RELEASE F,"BLAH"
END
END
That code will stop only for one person - for everyone else it will flow as normal. When it does stop, use the LIST-LOCKS command to see which file has a read lock for item "BLAH". That's your file! Don't forget to remove and recompile the code. Note that recompiling code while users are actively using it results in aborts. It's best to do this kind of thing after hours or on a test system.
If you can't modify the code like that, diagnostics like this can be difficult. If the above suggestions don't help, I think this challenge might be beyond your personal level of experience yet and recommend you get some help.
If suggestion here Does help, please flag this as the answer. :)

Linux Kernel Process Management

First, i admit all the things i will ask are about our homework but i assure you i am not asking without struggling at least two hours.
Description: We are supposed to add a field called max_cpu_percent to task_struct data type and manipulate process scheduling algorithm so that processes can not use an higher percentage of the cpu.
for example if i set max_cpu_percent field as 20 for the process firefox, firefox will not be able to use more than 20% of the cpu.
We wrote a system call to set max_cpu_percent field. Now we need to see if the system call works or not but we could not get the value of the max_cpu_percent field from a user-spaced program.
Can we do this? and how?
We tried proc/pid/ etc can we get the value using this util?
By the way, We may add additional questions here if we could not get rid of something else
Thanks All
Solution:
The reason was we did not modify the code block writing the output to the proc queries.
There are some methods in array.c file (fs/proc/array.c) we modified the function so that also print the newly added fields value. kernel is now compiling we'll see the result after about an hour =)
It Worked...
(If you simply extended getrlimit/setrlimit, then you'd be done by now…)
There's already a mechanism where similar parts of task_struct are exposed: /proc/$PID/stat (and /proc/$PID/$TID/stat). Look for functions proc_tgid_stat and proc_tid_stat. You can add new fields to the ends of these files.