While I understand it's best to start from the basics, I like to dabble. This is killing me though. In WoW, I use ElvUI and MyRolePlay (MRP) and the result is an issue with the enhanced tooltip. I've done quite a bit of editing to the code and the only thing left is trying to get this last line formatting properly - the entirety (3 variables) on one line. I don't understand what gtal is (or the "L"), but it seems to create a new line. Is there a way to combine the gtal lines, while retaining the RGB colors for both respectively? I've tried to stay within the code style (since I'm having trouble bringing in new code) but due to how the author calls for colors on the variables, I couldn't manage to get the final %s its own color value without making a brand new line.
local dC = GetQuestDifficultyColor(level);
local cC = RAID_CLASS_COLORS[ classunloc ];
Best I could come up with,
gtal( format( L["|r%s|cffffffff %s"], e, emptynil( mrp.DisplayTooltip.RA( f.RA ) ) or race, class), dC.r, dC.g, dC.b )
gtal( format( L["|r%s"], class), cC.r, cC.g, cC.b )
There's no information on gtal in the mod or anywhere else that I could find. I hear the author is impossible to approach. But I was hoping someone got the idea here.
Result of the two gtal lines Perfect, if only the last word was on the line above it!
If it helps, the block all this is in is
local dC = GetQuestDifficultyColor(level);
local cC = RAID_CLASS_COLORS[ classunloc ];
if level ~= nil and level < 0 then
e = L["|cffffffff(Boss)"]
else
e = format( L["|r%d|cffffffff"], level )
end
if mspsupported then
gtal( format( L["|r%s|cffffffff %s"], e, emptynil( mrp.DisplayTooltip.RA( f.RA ) ) or race, class), dC.r, dC.g, dC.b )
gtal( format( L["|r%s"], class), cC.r, cC.g, cC.b )
n = nil
t = nil
if f.FR and f.FR ~= "" and f.FR ~= "0" then
n = mrp.DisplayTooltip.FR( f.FR ) .. " "
end
and finally, this is what the original gtal looked like
gtal( format( L["%s %s |r%s|cffffffff (Player)"], e, emptynil( mrp.DisplayTooltip.RA( f.RA ) ) or race, class), r, g, b )
r, g, b = 1.0, 1.0, 1.0
Update - this is what works here, since if this were ever helpful to anyone else:
local dC = GetQuestDifficultyColor(level);
local cC = RAID_CLASS_COLORS[ classunloc ];
if level ~= nil and level < 0 then
e = L["|cffffffff(Boss)"]
else
e = format( L["|r%d|cffffffff"], level )
end
if mspsupported then
local classStr = format("|cff%02x%02x%02x%s|r", cC.r * 255, cC.g * 255, cC.b * 255, class)
local str = format( L["|r%s |cffffffff%s|r %s"], e, emptynil( mrp.DisplayTooltip.RA( f.RA ) ) or race, classStr)
gtal(str, dC.r, dC.g, dC.b)
gtal is defined in UI_Tooltip.lua:
--[[
EPIC KLUDGE!
Special local functions to overwrite and add the current tooltip.
]]
-- Single string
local function gtal( n, r, g, b )
local l = GameTooltip.mrpLines + 1
GameTooltip.mrpLines = l
r, g, b = (r or 1.0), (g or 1.0), (b or 1.0)
--if GameTooltip.mrpLines <= GameTooltip.orgLines then
-- Replace original line with ours, or add a new one if not there
if _G["GameTooltipTextLeft"..tostring(l)] then
if _G["GameTooltipTextLeft"..tostring(l)]:IsVisible() then
if _G["GameTooltipTextRight"..tostring(l)] then
_G["GameTooltipTextRight"..tostring(l)]:Hide()
end
_G["GameTooltipTextLeft"..tostring(l)]:SetText( n )
_G["GameTooltipTextLeft"..tostring(l)]:SetTextColor( r, g, b )
else
GameTooltip:AddLine( n, r, g, b )
end
else
GameTooltip:AddLine( n, r, g, b )
end
end
L is conventionally your localization table lookup, used here in case you want a different format string for a different language.
In this case, it looks like gtal always adds a line, so you need to do your work all in the same line. Fortunately, WoW gives you inline color overrides that you can use! See UI Escape Sequences - that's what's going on with |cxxxxxxxx and whatnot in the strings. You probably want something like:
-- Build a color-formatted class string
local classStr = format("|c%02x%02x%02x%s|r", cC.r, cC.g, cC.b, class)
-- Build your tooltip line, which consists of `$e $race $class`
local str = format( L["|r%s |cffffffff%s|r %s"], e, emptynil( mrp.DisplayTooltip.RA( f.RA ) ) or race, classStr)
-- Add the line to the tooltip
gtal(str, dC.r, dC.g, dC.b)
Related
I'm having troubles to define the objective fucntion in a SMT problem with z3py.
Long story, short, I have to optimize the placing of smaller blocks inside a board that has fixed width but variable heigth.
I have an array of coordinates (represented by an array of integers of length 2) and a list of integers (representing the heigth of the block to place).
# [x,y] list of integer variables
P = [[Int("x_%s" % (i + 1)), Int("y_%s" % (i + 1))]
for i in range(blocks)]
y = [int(b) for a, b in data[2:]]
I defined the objective function like this:
obj= Int(max([P[i][1] + y[i] for i in range(blocks)]))
It calculates the max height of the board given the starting coordinate of the blocks and their heights.
I know it could be better, but I think the problem would be the same even with a different definition.
Anyway, if I run my code, the following error occurs on the line of the objective function:
" raise Z3Exception("Symbolic expressions cannot be cast to concrete Boolean values.") "
While debugging I've seen that is P[i][1] that gives an error and I think it's because the program reads "y_i + 3" (for example) and they can't be added togheter.
Point is: it's obvious that the objective function depends on the variables of the problem, so how can I get rid of this error? Is there another place where I should define the objective function so it waits to have the P array instantiated before doing anything?
Full code:
from z3 import *
from math import ceil
width = 8
blocks = 4
x = [3,3,5,5]
y = [3,5,3,5]
height = ceil(sum([x[i] * y[i] for i in range(blocks)]) / width) + 1
# [blocks x 2] list of integer variables
P = [[Int("x_%s" % (i + 1)), Int("y_%s" % (i + 1))]
for i in range(blocks)]
# value/ domain constraint
values = [And(0 <= P[i][0], P[i][0] <= width - 1, 0 <= P[i][1], P[i][1] <= height - 1)
for i in range(blocks)]
obj = Int(max([P[i][1] + y[i] for i in range(blocks)]))
board_problem = values # other constraints I've not included for brevity
o = Optimize()
o.add(board_problem)
o.minimize(obj)
if (o.check == 'unsat'):
print("The problem is unsatisfiable")
else:
print("Solved")
The problem here is that you're calling Python's max on symbolic values, which is not designed to work for symbolic expressions. Instead, define a symbolic version of max and use that:
# Return maximum of a vector; error if empty
def symMax(vs):
m = vs[0]
for v in vs[1:]:
m = If(v > m, v, m)
return m
obj = symMax([P[i][1] + y[i] for i in range(blocks)])
With this change your program will go through and print Solved when run.
I am trying to find three parameters (a, b, c) to fit my experimental data using ODE solver and optimization by least squares using Scilab in-built functions.
However, I keep having the message "submatrix incorrectly defined" at line "y_exp(:,1) = [0.135 ..."
When I try another series of data (t, yexp) such as the one used in the original template I get no error messages. The template I use was found here: https://wiki.scilab.org/Non%20linear%20optimization%20for%20parameter%20fitting%20example
function dy = myModel ( t , y , a , b, c )
// The right-hand side of the Ordinary Differential Equation.
dy(1) = -a*y(1) - b*y(1)*y(2)
dy(2) = a*y(1) - b*y(1)*y(2) - c*y(2)
endfunction
function f = myDifferences ( k )
// Returns the difference between the simulated differential
// equation and the experimental data.
global MYDATA
t = MYDATA.t
y_exp = MYDATA.y_exp
a = k(1)
b = k(2)
c = k(3)
y0 = y_exp(1,:)
t0 = 0
y_calc=ode(y0',t0,t,list(myModel,a,b,c))
diffmat = y_calc' - y_exp
// Make a column vector
f = diffmat(:)
MYDATA.funeval = MYDATA.funeval+ 1
endfunction
// Experimental data
t = [0,20,30,45,75,105,135,180,240]';
y_exp(:,1) =
[0.135,0.0924,0.067,0.0527,0.0363,0.02445,0.01668,0.012,0.009]';
y_exp(:,2) =
[0,0.00918,0.0132,0.01835,0.0261,0.03215,0.0366,0.0393,0.0401]';
// Store data for future use
global MYDATA;
MYDATA.t = t;
MYDATA.y_exp = y_exp;
MYDATA.funeval = 0;
function val = L_Squares ( k )
// Computes the sum of squares of the differences.
f = myDifferences ( k )
val = sum(f.^2)
endfunction
// Initial guess
a = 0;
b = 0;
c = 0;
x0 = [a;b;c];
[fopt ,xopt]=leastsq(myDifferences, x0)
Does anyone know how to approach this problem?
Just rewrite lines 28,29 as
y_exp = [0.135,0.0924,0.067,0.0527,0.0363,0.02445,0.01668,0.012,0.009
0,0.00918,0.0132,0.01835,0.0261,0.03215,0.0366,0.0393,0.0401]';
or insert a clear at line 1 (you may have defined y_exp before with a different size).
I have an AMPL model file that I'm working to convert to GLPK. It begins:
param n; # The number of nodes in the graph
set V := {1 .. n}; # The set of vertices in the graph
set E within V cross V; # The set of edges in the graph
set NE within V cross V := {i in V, j in V: i < j} diff E;
set FIXED within V cross V default {}; # The set of demand pairs with fixed flow
When running this, I get the following error:
_test.mod:5: set expression following default must have dimension 2 rather than 1
Context: : i < j } diff E ; set FIXED within V cross V default { } ;
MathProg model processing error
This must be a syntactic difference between MathProg and its superset, AMPL—running the code in AMPL works perfectly. How does one express a 2D empty set in MathProg?
Alright, the hack of a solution is this:
set FIXED within V cross V default {i in V, j in V: 1 < 0};
Put an obviously false condition. It'll have the dimensionality you want and still be empty.
I am trying to solve equations and output the derivations. I have no problem solving for the derivation but when I try to output the derivation it always comes with the variable name, examples:
{{w0fromxfun1[x] -> (8.46504 miu^(4/9) qi^(4/9) (-1. x + xf)^(4/9))/
Ep^(4/9)}}
{{uave[x] -> (0.382926 Ep^(1/4) qi^(3/4))/(
hf (miu (-1. x + xf))^(1/4))}}
See this link for a better view
My code for solving the derivation is here:
equ5 = uave[x] == ((qi Ep^(1/3))/(
3.59623 hf (hf miu (xf - x))^(1/3)))^(3/4);
diffequsol2 = PowerExpand[FullSimplify[DSolve[equ5, uave[x], x]]] // N;
waveofthemaxes =
FullSimplify[
1/xf Integrate[w0fromxfun[x], {x, 0, xf}, Assumptions -> trivial]];
equ6 = w0fromxfun1[
x] == ((4.5788*(hf miu qi/((\[Pi]/4) hf ) (-x + xf))^(1/3))/Ep^(
1/3))^(4/3);
diffequsol1 =
PowerExpand[FullSimplify[DSolve[equ6, w0fromxfun1[x], x]]] // N
See here for a better view of the code
I don't want the variable names in front of the derivations, I tried Fullsimplify and simplify but don't work.
I have tried to write a function that takes in notes in MIDI form (C2,A4,Bb6) and returns their respective frequencies in hertz. I'm not sure what the best method of doing this should be. I am torn between two approaches. 1) a list based one where I can switch on an input and return hard-coded frequency values given that I may only have to do this for 88 notes (in the grand piano case). 2) a simple mathematical approach however my math skills are a limitation as well as converting the input string into a numerical value. Ultimately I've been working on this for a while and could use some direction.
You can use a function based on this formula:
The basic formula for the frequencies of the notes of the equal
tempered scale is given by
fn = f0 * (a)n
where
f0 = the frequency of one fixed note which must be defined. A common choice is setting the A above middle C (A4) at f0 = 440 Hz.
n = the number of half steps away from the fixed note you are. If you are at a higher note, n is positive. If you are on a lower note, n is negative.
fn = the frequency of the note n half steps away. a = (2)1/12 = the twelth root of 2 = the number which when multiplied by itself 12 times equals 2 = 1.059463094359...
http://www.phy.mtu.edu/~suits/NoteFreqCalcs.html
In Objective-C, this would be:
+ (double)frequencyForNote:(Note)note withModifier:(Modifier)modifier inOctave:(int)octave {
int halfStepsFromA4 = note - A;
halfStepsFromA4 += 12 * (octave - 4);
halfStepsFromA4 += modifier;
double frequencyOfA4 = 440.0;
double a = 1.059463094359;
return frequencyOfA4 * pow(a, halfStepsFromA4);
}
With the following enums defined:
typedef enum : int {
C = 0,
D = 2,
E = 4,
F = 5,
G = 7,
A = 9,
B = 11,
} Note;
typedef enum : int {
None = 0,
Sharp = 1,
Flat = -1,
} Modifier;
https://gist.github.com/NickEntin/32c37e3d31724b229696
Why don't you use a MIDI pitch?
where f is the frequency, and d the MIDI data.