Makefile: updating variables [duplicate] - variables

This question already has answers here:
Closed 11 years ago.
Possible Duplicate:
arithmetic in a Makefile
I'm very much a beginner using Makefile. I would like to update a variable, like this more or less:
LEVEL=0
train:
while (eval_score > previous_eval_score)
make iterate
iterate:
do stuff
write files to /path/to/$(LEVEL)/asdf.txt
$(LEVEL)++
In other words, every iteration writes some files to a directory, first to /path/to/0, then /path/to/1, etc. until some threshold is reached.
So apparently it's not allowed to update or reassign a variable inside a function. I have searched for a while now but can't find any satisfactory answers. Maybe I have but I don't understand everything. I have also tried stuff like calculating in bash but eventually I still have to update the variable. Perhaps I should try something like update a file instead and for every iteration, just read from the file?
Thanks for your time.

The main problem with your Makefile is that each make iterate spawns a sub-make, which could update its environment variables, but with no effect on the parent make and thus no effect on the next iteration. In addition, you cannot update variables from within rules, but that is a secondary problem.
You can do iterative make just like you suggested and increment the level via the shell:
train:
LEVEL=0; while need_more_iterations; do \
$(MAKE) LEVEL=$$LEVEL iterate; \
LEVEL=`echo $$LEVEL + 1 | bc`; \
done

Related

Cmake commands as macro arguments [duplicate]

This question already has answers here:
How to call a function in CMake whose name is stored in a variable
(5 answers)
Closed 11 months ago.
I want to use a CMake macro as a text replacement tool to call a command. This is something I am familiar with in C, but I am not sure if this is allowed in CMake.
what I want to be able to do:
MY_MACRO(
MY_COMMAND(ARGS)
)
I have tried a few different variations on this general idea on how to implement this, but I am not sure it is possible.
MACRO(MY_MACRO)
# do stuff
${ARGN} # Call MY_COMMAND
# do stuff
)
I figured this out based on this thread:
https://gitlab.kitware.com/cmake/cmake/-/issues/20800#note_951424
I haven't tested very thoroughly, but this is the gist at least:
MACRO(MY_MACRO)
#stuff
CMAKE_LANGUAGE(EVAL CODE ${ARGN})
#stuff
ENDMACRO(MY_MACRO)

SCIP - run (nearly) same LP on different instances

I have an LP, formulated in the modelling language Zimpl, that I want to run on many instances, which are in different files.
Additionally, I want to change one parameter in this LP.
For a single call, my file test.zpl looks like this:
param FILE := "file1.dat"
param BOUND := 42
[test_body: Rest of LP]
Now I want to change those two parameters. SCIP has the -c option, to execute some command. But I cannot find by which command to achieve this. All parameter changes I found affect the algorithm, not the data.
The command change to change the problem does not seem to allow new parameters/variables.
In the end, I expect the solution to look something like
scip -c "[set my parameters]; read test_body.zpl; optimize; quit"
How do I set these problem parameters?
I am not aware of any commands that support the modification of model parameters as you wish. However, if you don't hardcode the value of param BOUND in the .zpl file (instead, move the value to the .dat file and use a proper read command in the model), then you could procede as follows:
Make a copy of your data file such that each copy contains a distinct value of param BOUND
Call scip.exe separately with each data file (you could also use a simple batch script)

Can't delete sysmis spss variables

Need to delete spss variable without the data (sysmis data)
The command IF(SYSMIS(V1)) DELETE VARIABLES V1. doesnt' work.
The IF command does not work in this way, that you are attempting. It operates on a case by case basis i.e. so IF a case matches a certain criteria THEN apply a certain transformation to THAT CASE ONLY (not a variable as a whole).
If you do not dynamically need to search for empty variables (which is possible with python - see below) then all you need is the DELETE VARIABLES command (or alternatively ADD FILES or MATCH FILES command all achieving exactly the same result - with the exception of DELETE VARIABLES requiring no pending transformations so in which case I personally prefer ADD FILES or MATCH FILES).
Any one of these 3 commands should suffice:
DELETE VARIABLES v1.
ADD FILES FILE=* /DROP=v1.
MATCH FILES FILE=* /DROP=v1.
If however, you need to dynamically check if a variable is empty and then only delete it, then you can use python to do so.
You will need to have python integration installed and correctly setup for your version of SPSS and spssaux2 module downloaded and saved in the appropriate location where SPSS can find it, for the below to work:
DATA LIST FREE / A B C D.
BEGIN DATA
1 2 3 4 5 6 7 8 9 10 11 12
END DATA.
COMPUTE C=$SYSMIS.
DATASET NAME DSSIM.
BEGIN PROGRAM.
import spssaux2
spssaux2.FindEmptyVars(delete=True)
END PROGRAM.
SYSMIS doesn't refers to variables but cells. From your approach you have to ;
COUNT(SYSMIS(V1)) and if its equal to your case(row on data file) count then you can DELETE VARIABLES V1.

How exactly do you use variables in Jenkins?

Can someone concisely explain what the differences between the three variables below are? Because in all honesty, when I create a Jenkins job, I randomly guess between the three types until something works, but I'd love to understand rather than blindly picking.
${ENV,var="BUILD_USER"}
${BUILD_USER}
$BUILD_USER
Also, are there other ways of writing variables in Jenkins that I missed other than the 3 ways above?
When used in a statement:
${ENV,var="BUILD_USER"}--evaluates the system environment variables and returns the value for the variable BUILD_USER.
example: curl ${ENV,var="BUILD_USER"}/api/xml
${BUILD_USER} --returns the value of the BUILD_USER variable in the current script memory space.
example: curl ${BUILD_USER}/api/xml
$BUILD_USER--used to assign values to the BUILD_USER variable.
example: $BUILD_USER = "BUILD_USER"
In general, variable expansion is up to the plugin that interprets a configuration value.
For example, if you set up a job parameter GIT_REPOSITORY and use it to configure an address where git clone should go by putting $GIT_REPOSITORY into the git repository field, it works, but only because the Jenkins git plugin has implemented variable expansion support.
Many plugins do implement it but you cannot know it unless you test it. However, these days the support is so common it is safe to assume it should work.
Both forms of reference, $VAR and ${VAR}, work and are equivalent. The latter form is useful if you need to use the variable in a place where it is surrounded by other characters that could be interpreted as part of variable, like $VARX (Jenkins would be looking for variable named VARX) and ${VAR}X (Jenkins understands the variable is named VAR).
These rules have been modeled after variable expansion rules in Unix shells. Indeed, the job variables are made available as environment variables to build steps and in the Unix shell build step the variables are used the same way as above.
In a Windows CMD build step the variables are again used like any Windows environment variable: %VAR%.

SCIP write best feasible solution in automated test

Based on steps in http://scip.zib.de/doc/html/TEST.php, I have managed to set up an automated test using SCIP. However, I'd like to write the solution (best feasible solution) to a file, instead of just getting the objective value. Is there anyway to do it in the automated test?
I did a hack in check.sh by replacing
OPTCOMMAND=optimize; write solution myfilename.sol;
But too bad, it doesn't seem to work, when I tried to make TEST=mytest test, this line is observed from the output
bash ./check.sh mytest bin/scip-3.1.0.linux.x86_64.gnu.opt.spx default scip-3.1.0.linux.x86_64.gnu.opt.spx 3600 2100000000 6144 1 default 10000 false false 3.1.0 spx false /tmp optimize;
write: solution is not logged in on myfilename.sol
I know it is possible to write the solution via interactive shell, but I am trying to automate the test in order to retrieve both solution and obj value. Any help or clarification will be much appreciated!
You are getting an error because with the syntax you are using, you try to invoke a bash command called "write" because of the semicolon:
The write utility allows you to communicate with other users, by
copying lines from your terminal to theirs.
Just try without semicolon ;)
The cleaner solution would be to modify the file "check/configuration_tmpfile_setup_scip.sh"
and add the line
echo write solution /absolute/path/to/solutions/${INSTANCE}.sol >> $TMPFILE
before the quit command. This configuration file sets up a batch file to feed SCIP with all commands that the interactive shell should execute, and you can model arbitrary user behavior.