GAMS: I think I have a pretty simple question, however I'm stuck and was wondering if someone could help here.
A simplified version of my model looks like this:
set(i,t) ;
parameter price
D;
variable p(i,t)
e(i,t);
equations
Equation1
obj.. C=sum((i,t), p(i,t)*price);
Model file /all/ ;
Solve file minimizing C using MIP ;
Display C.l;
p(i,t) and e(i,t) are related:
Equation1 .. e(i,t)=e=e(i,t-1)+p(i,t)*D
Now I want to retrieve information from the solution: lets say I want to know at what t e(i,t) has a certain value for example --> e(i,t)= x(i) or otherwise formulated e(i,t=TD)=x(i) find TD, where x(i) thus is depending on i. Does anyone know how I can write this in to my GAMs model? To be clear I do not want to change anything about my solution and the model I have runs; I just want to retrieve this information from the solution given.
So far I tried a couple of thing and nothing worked. I think that this must be simple, can anyone help? Thank you!
Try something like this:
set i /i1*i10/
t /t1*t10/;
variable e(i,t);
*some random dummy "solution"
e.l(i,t) = uniformInt(1,10);
set find5(i,t) 'find all combinations of i and t for which e.l=5';
find5(i,t)$(e.l(i,t)=5) = yes;
display e.l,find5;
Hope that helps,
Lutz
Related
I'm facing a very concrete problem with python-click 8.1.3. The helptext created by Click wastes too much column space when an option name is a tad long. Depicted in picture below:
I trace into Click's source code, and pinpoint a hardcoded value in HelpFormatter.write_dl(), the col_max parameter determines first-column max-width, which is 30, and I hope to reduce it to 16.
As a Click-library user, how can I achieve this without modifying Click's source code? Maybe some class inheritance or patching trick?
Thank you in advance.
You can do something like this:
class MyHelpFormatter(click.HelpFormatter):
def write_dl(self, rows, col_max=5, col_spacing=2):
super().write_dl(rows, col_max, col_spacing)
click.Context.formatter_class = MyHelpFormatter
Check this answer for a similar example
I've downloaded saveppt2, jrichter's code and even WritetoWordfromMatlab and tried reading through them to figure it out with no luck. I have something of my own built already so I just need to figure out how to get tables to work.
Whenever I try something like:
myTable.Cell(1,1).TextFrame.Text = 'textstring'
or
myTable.Table.Cell(1,1) = 'textstring'
Or any combination of table / text commands I end up with there being no such property or function as cell for table objects. Every COM/VBA/C library I can find, as well as some code in Python (PandastoPowerPoint from Github) that does what I'm aiming to do says that Table.Cell(row,col) should work. Is this specifically a problem with matlab trying to use (#,#) as a form of indexing?
Try
myTable.Cell(1, 1).Shape.TextFrame.TextRange.Text = "TextString"
or = 'TextString' if that's what matlab prefers.
Thanks Steve R! With a little tweak, I got it to work, finally. So here's the answer:
% add table to existing slide object
myTable = slide.Shapes.addTable(nRows,nCols,x0,y0,rowWidthnRows,colHeightnCols)
myTable.Table.Cell(1, 1).Shape.TextFrame.TextRange.Text = 'TextString'
I am new to python.I am posting here for the first time and I know question might be quite basic but problem is I can't figure out myself.
Lets say I have
List=[("a,"b"),("c","d"),("e","f")]
I want the user to enter one of the elements of one of the tuples as input and the other element is printed.Or more precisely I would say that just one of elements in List[x][0] is input and corresponding List[x][1] element is printed as output.I hope it makes sense.
Thanks!
Please check List in the question.I think you forgot a quote(") in the first tuple.[("a^here,"b"),("c","d"),("e","f")]
I think this might help you.
List=[("a","b"),("c","d"),("e","f")]
c=raw_input('ENTER A CHARACTER-')
for i in xrange(len(List)):
if c in List[i]:
ind=List[i].index(c)
print List[i][abs(ind-1)]
break
I am using Matlab to read a workbook with a bunch of sheets in it.
I do some calculation and have to update one particular column in one sheet. I tried using xlswrite after xlsread, it does not work.
So, my code looks something like:
[~,~,Data] = xlsread('MyFile.xlsx', 'MySheet');
Data(2:end-1,5) = Data(2:end-1,5) + 1.5; %Random operation for illustration only
ret = xlswrite('MyFile.xlsx',Data,'MySheet');
But ret is 0. So, I am not able to achieve replacement process. Can you please help.
Thanks
Based on my own comment:
Please use the second output argument as well an check what message you get:
[status,message] = xlswrite(filename,A,sheet)
Hopefully that is sufficient to find the cause, please let us know if that's the case.
Apparently it was indeed sufficient for the asker.
I've been looking throught the documentation, but can't seem to find the bit I want.
I have a for loop and I would like to be able to view every value in the for loop.
for example here is a part of my code:
for d = 1 : nb
%for loop performs blade by blade averaging and produces a column vector
for cc = navg : length(atbmat);
atb2 = (sum(atbmat((cc-(navg-1):cc),d)))/navg;
atbvec2(:,cc) = atb2;
end
%assigns column vector 'atbvec2' to the correct column of the matrix 'atbmat2'
atbmat2(d,1:length(atbvec2)) = atbvec2;
end
I would like to view every value of atb2. I'm a python user(new to MATLAB) and would normally use a simple print statement to find this.
I'm sure there is a way to do it, but I can't quite find how.
Thankyou in advance.
you can use disp in Matlab to print to the screen but you might want to use sprintf first to format it nicely. However for debugging you're better off using a break point and then inspect the variable in the workspace browser graphically. To me, this is one of Matlab's best features.
Have a look at the "Examine Values" section of this article
The simplest way to view it everywhere is to change this line:
atb2 = (sum(atbmat((cc-(navg-1):cc),d)))/navg;
Into this, without semicolon:
atb2 = (sum(atbmat((cc-(navg-1):cc),d)))/navg
That being said, given the nature of your calculation, you could get the information you need as well by simply storing every value of abt2 and observing them afterwards. This may be done in atbmat2 already?
If you want to look at each value at the time it happens, consider setting a breakpoint or conditional breakpoint after the line where abt2 is assigned.