I have set i/1*7/ and parameter u(i) /1 15,2 5,3 15,4 30,5 21,6 30,7 11/
I want to find maximum element of u(i) , i use 'smax' , I write this code:
set j/1*7/;
parameter u(i) /1 15,2 5,3 15,4 30,5 21,6 30,7 11/;
scalar max_val;
max_val=smax(j,u(j));
To find the index of maximum element, I wrote this
set posmax(j) 'position of largest element on deg(j)';
posmax(j) = deg(j) = max_val ;
There are two maximum members here, but I just want one.for example iwant to have posmax=6 , or posmax=4 . but i dont want posmax = 6,7.
What command should i use?
How can I access the first member?
In general, how can I access a particular member in a subset?
i write posmax('1') but i get error.
Scalars mypos;
Mypos=smin (j$posmax(j) ,j.val);
Related
I have a matrix, of dimension, i rows and j columns, a specific element of which is called x(i,j), where say i are plants, and j are markets. In standard GAMS notation:
Sets
i canning plants / seattle, san-diego /
j markets / new-york, chicago, topeka / ;
Now, I also wish to create a loop, over time- for 5 periods. Essentially, say I define
Set t time period
/period1
period2
period3
period4
period5
/ ;
Parameters
time(t)
/ period1 1,
period2 2,
period3 3,
period4 4,
period5 5
/ ;
Basically, I want to re-run this loop, which contains a bunch of other commands, but I wish to re-define this matrix from period 2 onwards, to look like this:
x("seattle",j)=x("seattle",j)+s("new-york",j)
x("new-york",j)=0'
Essentially, within the loop, I want the matrix x(i,j) to look different after period 2, wherein the column x("seattle",j) is replaced with the erstwhile x("seattle",j)+s("new-york",j) and the column x("new-york",j) is set to 0.
The loop would start like :
loop
(t,
...
Option reslim = 20000 ;
option nlp = conopt3 ;
solve example using NLP maximizing VARIABLE ;
) ;
I am not sure how to keep redefining this matrix within the loop, for each period>2.
Please note: After period 2, the matrix looks the same. The change only happens once (i.e., the matrix elements do not keep looping from the previous period, but just switch once , at the end of period 2, and then stay constant thereafter.
Any help on this is much appreciated!
You can use a $ condition to make this change in the loop for period2 only, like this:
x("seattle",j)$sameAs(t,'period2')=x("seattle",j)+s("new-york",j);
I have a list:
#{IFUP} 10 20
I want to modify only one of those values, e.g:
${IFUP}[${idx}]= Set Variable 30
where $idx is 0
This produces No keyword with name ''${IFUP}[${idx}]='. Same happens with direct ${IFUP}[0] assignment.
RobotFramwork version is 3.1 (list syntax is a bit different).
I would be happy with a variable variable solution like: ${IFUP_${idx}}= but this produces the same error.
Suggestions?
You can use the 'Set List Value' keyword from Collections library.
In your case, it should be
Set List Value ${IFUP} 0 30
http://robotframework.org/robotframework/latest/libraries/Collections.html#Set%20List%20Value
Please check below code:
List_at_place_change
#{IFUP} Create List 10 20
Log ${IFUP[0]}
Set List Value ${IFUP} 0 30
Log ${IFUP}
Below is the query that will give the data and distance where distance is <=10km
var s=spark.sql("select date,distance from table_new where distance <=10km")
s.show()
this will give the output like
12/05/2018 | 5
13/05/2018 | 8
14/05/2018 | 18
15/05/2018 | 15
16/05/2018 | 23
---------- | --
i want to use first row of the dataframe s , store the date value in a variable v , in first iteration.
In next iteration it should pick the second row , and corresponding data value to be replaced the old variable b .
like wise so on .
I think you should look at Spark "Window Functions". You may find here what you need.
The "bad" way to do this would be to collect the dataframe using df.collect() which would return a list of Rows which you can manually iterate over each using a loop.This is bad cause it brings all the data in your driver.
The better way would be to use foreach() :
df.foreach(lambda x: <<your code here>>)
foreach() takes a lambda function as argument which iterates over each row of the dataframe without bringing all the data in the driver.But you cant use a simple local variable v inside a lambda fuction when there is overwriting involved.you can use spark accumulators for such a case.
eg: if i want to sum all the values in 2nd column
counter = sc.longAccumulator("counter")
df.foreach(lambda row: counter.add(row.get(1)))
I have a set j and parameter edge. I have a graph too.
Set j/1*5/;
Alias(j,jp);
Parameter edge(j,jp)
That edge(j,jp) =1 if there is arc from j to jp , and it's 0 if there isn't arc from j to jp.
I maked edge(j,jp) .
I want to define a set or parameter , for saving index of neighborhood of node "j".
I Mean , neighborhood (j)={jp : edge(j,jp)=1}
I write ,below command but I get error.
Set neighborhood (j)
Neighborhood (j)$edge (j,jp) =JP.val;
How can I obtain neighborhood of especial node?
Do you work with an directed graph and assume there is just one neighbor for each j? Then, try this:
Set j/1*3/;
Alias(j,jp);
Parameter edge(j,jp) / 1.2 1, 2.3 1, 3.1 1 /;
Parameter Neighborhood (j);
Neighborhood (j) = sum(jp$edge(j,jp), jp.val);
Otherwise: What do you expect to see in Neighborhood, if there is more than one neighbor?
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.