lpsolve - how to define variable to accept values only from two intervals - optimization

I need to set up all my variables to accept only values from two intervals, e.g. for var C1:
C1 = 0 or
100 <= C1 <= 1000
and so on for each variable.
I can specify either first (=0) or second ([100;1000]) constraints for every variable but I need lpsolve model to to be able to assign either 0 ot any value from given interval.
Any advice appreciated.

Related

system missings when computing variable

I'm trying to compute a new variable using 3 other variables. If all 3 conditions are positive, the new variable gives 1. My problem: if just 1 or 2 of these conditions are present, I get a value 0 when it needs to be a system missing.
In order to get SPSS to calculate a value only when you have values in all three variables you can use this:
if nmiss(E’sept_preTx, Eope’gem_preTx, TRpieksnelheid_t1)=0
DD_new=(E’sept_preTx < 10) & (Eope’gem_preTx >= 15) & (TRpieksnelheid_t1 > 2.8).
the nmiss counts the missing values, and the original calculation is carried out only if tere are none.

How to check if weight is between two values

What's the best way to check if weight are between the range using the If condition?
Ex:
If textbox.text (between) value X - value Z then
You can use standard equal operators like this:
If (Val(TextBox.Text) >= ValueX) And (Val(TextBox.Text) <= ValueZ) Then
' etc...
Val function extracts numbers from string.

Sum of variable changing over time (AMPL)

I have a time dependent variable that changes with some predefined timesteps. I would like get the sum of the variable over the course of several timesteps. How can I write the sum of the variable?
.mod file:
set Time default {}; #number of timesteps
param top{Time}; #number of hours in each timestep
var E{Time} >= 0.001; #the timedependent variable
subject to annualElectricity{t in Time}:
Ea = sum{E[t]*top[t]};
.dat file:
set Time := 1 2 3 4 5 6;
param top := #operating time (hours)
1 609
2 321
3 532
4 425
5 351
6 7
;
I'm guessing that the annualElectricity constraint collection that you have declared is your attempt to do what you want, but I'm not sure you want to use a constraint for that.
If you want to sum all variables in the collection E, the sum expression will be sum{t in Time} E[t]. If you want the sum of all products E[t]*top[t], the sum expression will be sum{t in Time} E[t]*top[t].
If you won't need this value to solve the problem, you can declare a param Esum and then, after you have solved the problem, you can call let Esum := sum{t in Time} E[t]. But if you need this value in your problem, I believe you can define a variable var Esum = sum{t in Time} E[t] and use it in your constraints/objective function.
I can see you are new to AMPL, so you may benefit from reading some basic AMPL introduction, such as this https://pifop.com/help/ampl_programs.html that I've written.

Possible to store a value in variable in SPSS?

Is is possible in SPSS to store a value in a variable (not a variable created in a data set)?
For example I have a loop for which I want to pass the value 4 to all the locations in the loop that say NumLvl.
NumLvl = 4.
VECTOR A1L(NumLvl-1).
LOOP #i = 1 to NumLvl-1.
COMPUTE A1L(#i) = 0.
IF(att1 = #i) A1L(#i) = 1.
IF(att1 = NumLvl) A1L(#i) = -1.
END LOOP.
EXECUTE.
You can do this using DEFINE / !ENDDEFINE SPSSs Macro Facility, for example:
DEFINE !MyVar () 4 !ENDDEFINE.
You can then use !MyVar as a substitute for 4 wherever in your syntax you wish.
See DEFINE / !ENDDEFINE documentation for further notes.

C or Obj-c function to normalize range to x-y

I have an output of ranges from 150-0. I want to map those to 0 to 1. Or perhaps 0 to (some value less than 1 such as 0.5) where 150 is 0 and 0 is 1 ( or some values less than..).
Is this considered interpolation? What is the formula to derive these values? But preferably, is there a built-in StdLib function I can call?
Divide your number by the (Max - min). This would make 150 be 1 and 0 will be 0, with everything else a number in between. Now, to make it the opposite just do 1 - result.
If you need to map 0-1 to any custom range, you need to multiply range with MAX-MIN and then add MIN to it to get the exact number in range.
Formula will be MIN + (MAX-MIN)*value
where value is range in between 0-1;
MIN is number mapped to 0;
MAX is number mapped to 1;