How to set an upper bound over all elements of a set in gams - linear-programming

I have been trying to do the below code, which attempts to set the upper bound of every element of set J to 3.
set J /a1, a2, a3/;
positive variables b(J);
variable obj;
equations cons1, goal;
cons1..
b.up(J) =e= 3;
The rest of the GAMS code just runs the model. However, the generated error statement says "Uncontrolled set entered as constant". I have also tried "b.up(J) = 3;" -- Get the same problem. Does anyone know how to solve this? This problem is similar (How to set upper and lower bounds for each element in a set?), but is actually not my solution.

You can define upper bounds in two ways: Formulating an equation or using the .up suffix. You mixed the two ways which causes problems.
This is the first way, defining an equation:
Equation cons1(J);
cons1(J)..
b(J) =l= 3;
If you use the suffix approach (which is the niceer one), you should not use an equation, just do:
b.up(J) = 3;

Related

If Statement giving value error

I am trying to compare two data ranges to determine if they are the same or not.
I'm using the following statement and I get a #Value! error message:
=IF(SUM(ABS(B2:E7-G2:J7))=0,"Same", "Not")
If you are looking to see if the arithmetic total of the numbers in the two ranges is the same then this standard formula should do.
=IF(SUM(B2:E7)-SUM(G2:J7), "Not", "Same")
A zero in Excel evaluates to a boolean FALSE. Anything that is not false is TRUE.
This does not determine whether each cell directly corresponds to its 'sister' cell in the other range; only that the sum total of each is equal or not. The values in different cells could be interchanged or by coincidence be offset from one another in a perfect proportion to create an equal sum.
If you require a cell by cell analysis, then a much more complicated formula could be provided.
=IF(SUMPRODUCT(--(B2:E7=G2:J7))=24, "Same", "Not")
24 being the total number of cells in each range. While this does not require Ctrl+Shift+Enter, a SUMPRODUCT function does produce cyclic calculations.
Do you have strings in your answer or have the formula in row 1 or 8+? If yes that might be the reason as the formula works correctly assuming you
hit ctrl+shift+enter and
have only numbers in the ranges
For a general solution try
{=IF(AND(B2:E7=G2:J7),"Same","Not")}
Do not forget to hit ctrl+shift+enter as otherwise it will only look at the row the formula itself is in!

How to create a list of numbers 1-1000 to simplify?

I am working on a "Whats my number?" program (http://goo.gl/upgkZ2) as posted on reddit and I was wondering if there was a way I could have a list of numbers 1-1000 and remove groups of numbers that follow a certain criteria. I was wondering if there was any simpler way to do this?
You can create a list of 1-1000 in a simpler way by using:
tons = list(xrange(1000))
You don't actually need a list at all to solve this problem (well, find the two solutions to this problem). Loop over the numbers and continue (return to the top of the loop for the next iteration) for each condition that fails to be met:
for i in xrange(10,1001):
s_i = str(i)
if '1' in s_i or '7' in s_i:
continue
if sum([int(d) for d in s_i]) > 10:
continue
...
print i, 'satisfies the conditions.'
You need to use filter on the initial list removing each case one at a time
For efficiency, cut out the biggest ones first, like the last case removes 90% of the list
You can also use numpy to create an array:
import numpy as np
a=np.arange(1,1001)

Maximum number of Bishops that can be placed on a NxN Chessboard - SPOJ

Using the Constant time formula for Maximum bishops on a chessboard, which is:
int maxBishops(N) return 2*(N-1);
Implemented for the value of N lesser than 10^100, as follows: https://ideone.com/lvuiXW
Verified using Wolfram|Alpha but getting wrong answer on SPOJ's BISHOPS submission.
Am I missing something in the algorithm or is it an implementation issue?
A long sequence of all '0' will make your program fail.
Maybe you should also check for inputs not being a number.
EDIT:
The input case 500000000000001 seems to fail also.
I guess it will just print the carry.

Finding negative numbers in a field in ILog

I have a following requirement in Ilog Jrules,
Having an Integer field that contains both positive and negative numbers.
Requirement is to loop through the Integer field, find and remove the negative sign in the negative numbers.
It sounds simple but I could n't find a way to to this.
Any help or pointers would be highly appreciated. Many thanks.
(Supposing that XArray is an input/output Array of Integer in your rule project)
You can create a rule like this:
definitions
set 'x' to a Number from XArray;
if
x is less than 0
then
set x to -x;
PS: don't forget to add the rule in a ruleTask (with RetePlus Alogorithm: default) in the main ruleflow.
I ve created the following function in BOM to XML mapping and passing all the incoming integer field values through this, which solved the problem.
if (integer < 0)
return integer * -1;
else
return integer;

comparing three cells in openoffice calc. (i'd be happy with 2)

I need to do a simple function that is driving me nuts.
I have 3 columns with cells filled as follows.
I2 Y
I3 N
I4 Y
I am looking for every row that has N N N. I'm trying to formulate it so I can do a visual inspection but (baby steps) my first stage is failing. I'm trying
=IF(I2='N';'Y';'N')
In this case the output should be 'Y', Instead I'm getting #VALUE.
Any pointers?
try using double quotes and that should do it
=IF(A1="y";"y";"n")
this works for me