How can I solve problems iteratively in CVXPY? - cvxpy

I want to solve a problem, then use that problem's variables in another problem's constraints, solve it, use the second problem's variables in a third problem's constraints, and so on until the distance between the nth and the (n-1)-th variables is small enough.

Related

How to structure complicated table elements

Normally tables are easy to manage , especially since autolayout can do most of the heavy lifting to determine cell sizes and so on. However, there are cases where things become a little bit more tricky like having a table of polls.
A poll in this case consists of labels with variable description lengths, images with varying sizes and a set of options for the user to choose from ( a nested table essentially ).
----Approach 1------
Break each poll into a number of cells
Pros:
Its easy to add more fields to a poll in the future, layout is easier to handle for a single cell for each element especially in the case of the nested table. If you need to fall back to manually calculating the size of a specific cell you can do it while keeping everything else on automatic.
Cons:
If you have multiple polls you need to keep track which cell corresponds to which poll, and you generally need to do some arithmetic to keep track of whats what.
----Approach 2-----
Have the poll that contains all these elements be one big cell and set the constraints between them appropriately.
Pros:
Its easy to implement, maps your model to your cell in a one to one fashion without having to multi-demultiplex your data.
Cons:
Autolayout can get hairy with nested tables. For example, for the height of the cell in this case, i used to return UITableViewAutomaticDimension until i realised this wont cut it as a nested table exists that could be any kind of size. Its quite straightforward to calculate the contentsize of the nested table, however, this would mean you would have to calculate ALL of the other elements as well as now you're returning a specific height and not automatic. Your job has become that much harder.
----Outro----
How do you approach issues like that? Approach 1, 2 or something entirely different? I've simplified the structure of the elements here to make things a bit more readable, there's more arcane stuff involved like shadowed views containing the elements you see to create the illusion of a floating card etc.
Thanks everyone.
P.S : If there's already an answer about this somewhere please point me towards that, i just haven't found much on this yet. Hopefully this post can spark some discussion on the matter and help other people in my shoes.
A straightforward alternative suggested by Paulw11 is to use sections and Approach 1. Even though this may not cover cases that have tables within tables within tables, it will suffice for what I imagine is mostly every conceivable case that has a respectable UI.

Fitting more systems on the first page of a Lilypond score

I'm working to improve upon an excellent sheet I found of Debussy's Deuxième Arabesque on the freely available Mutopia Project.
In particular, I'm interested in fitting the music on fewer pages but I struggle to have the first page display five systems instead of four with the version I arrived at.
From the reproduction above, I would like the fith system (starting at bar 13) to be at the bottom of the first page. It seems there are a lot of wasted space on the first page and I'm rather confident it will fit perfectly.
I have a hard time playing figuring out how to achieve this. I have displayed the spacing annotations as advised by the documentation but I do not seem to be able to make sense of it.
If I were typesetting this today, I would try changing the staff size, like this:
#(set-global-staff-size 18)
You can add the following to your paper block
\paper {
min-systems-per-page = #5
system-system-spacing.padding = #2 %fit staves closer together
system-system-spacing.stretchability = #15 %how flexible the spacing is
}
This will of course force that all other pages have at least five systems. You can play around with the padding and stretchability values and see what works best. Also, you might want to make the staves smaller than the default 20pt. To do that, you can add the following at the beginning of the file:
#(set-global-staff-size 18)

Efficiently Computing Text Widths

I need to compute the width of a column with many rows (column AutoSize feature). Using Canvas.TextWidth is far too slow.
Current solution: My current solution uses a text measurer class that builds a lookup table for a fixed alphabet once and then computes the width of a given string very fast by adding up character widths retrieved from the lookup table. For characters not contained in the lookup table, the average character width is used (also computed once).
Problem: This works well for European languages but not for Asian languages.
Question: What's the best way to tackle this problem? How can such an AutoSize feature be realized without the relatively slow Canvas functions and without depending on a specific alphabet?
Thanks for any help.
You said you want to get the maximum text width for a column. Can't you, say, take only the 4 or 5 longest strings and get their widths? That way you won't have to find the width for all items and can save quite some time.
Or you use your cache to find the rough length of the strings and then refine that by getting the actual width for the top 4 or 5 items you found.
I don't think it matters a lot whether you use Canvas.TextWidth or GetTextExtentPoint32. Just use one of these to get the exact widths, after you used one of the methods above to guesstimate the longest/widest strings.
To those who think this doesn't work
If the poster of the original question thinks it could work, I have no reason to think it won't. He knows best what kind of strings can be in the columns he has.
But that is not my main argument. He already wrote that he does a preliminary textwidth by adding the predetermined individual widths of the characters. That does not take into account any kerning. Well, kerning can only make a string narrower, so it still makes sense to check only the top 4 or 5 items for the exact width. The biggest problem that can occur is that the column could be a few pixels too wide, no more. But it will be a lot faster than using TextWidth or GetTextExtentPoint32 or similar functions on each entry (assuming more than 5 entries), and that is what the original poster wanted. I suggest that those who don't believe me simply try it out.
As for using the pure string length: even that is probably good enough. Yes, 'WWW' is probably wider than '!!!!!', but the original poster will probably know best wat kind of string material he has, and if it is feasible. '!!!!!' or 'WWW' are not the usual entries one expects. Especially if you consider that not only one single string is checked, but the longest 4 or 5 strings (or whatever number turns out to be optimal). It is very unlikely that the widest string is not among them. But the original poster can tell if that is possible or feasible. He seems to think it is.
So stop the downvoting and try it out for yourself.
I'm afraid you have to use Canvas.TextWidth, or your implementation will be imprecise. The width of text depends on the font kerning, where different character sequences may have different widths (not just the total of individual character widths).
Me, I cut out the middle-man and use the Windows API directly. Specifically, I use GetTextExtentPoint32 with the .Handle of the Canvas. There's nothing you can do to be faster, other than caching results in some way, and frankly you'll just add overhead.

Shifting elements in match3 kind of game

I am a beginner at ActionScript3, and for my learning purpose, I am trying to build a match3 kind of game. I am making is a clone of bejeweled kind of game. but instead of swapping, I have to delete those elements and shift the upper elements down and add new elements above those shifted elements.
I am able to delete matched elements and after matching I'm removing those elements but I am stuck with the shifting code. I am not able to shift those elements down.
I believe that you should take a look at Richard Lord's Tetris source code as your game may be somehow similar in mechanics to Tetris. Tetris shifts down rows when you get lucky.
Richard Lord is one of the Flash Gurus and his way of doing things may seem pretty advanced for a starter like you. Take a look over the source code and see if it fits you. What I can tell is that this is the proper way to make a game but maybe it's not the best point to start for a novice like you that is in urgent need.
http://www.richardlord.net/blog/actionscript-3-tetris-source-code
I would approach it like this in 2 parts.
Loop through your array of board positions starting from the bottom row and check for an empty unoccupied slot, if you find one do another loop through the row above till you find a piece on the same column. If you find a piece on the row above apply a tween to move it down to the empty slot and continue your loop.
Once you have looped through all rows, and animated all the tweens you need to loop through again to find all the gaps that need gems dropped into them. Create new elements at those positions and then move them up by (element height * row), apply another tween to animate them back to their starting position.

Create jQuery Slider Range With One Handle Not Using Min/Max

Is there any possible way to create a slider that will create a range similar to what is done with one handle using min/max, only instead of min/max, starting the range from say 50 (on a scale from 1-100)? I realize this will most likely require modification of the slider or creating a plugin, just wondering if anyone has done this already or knows how to go about it.
I.e. something like this: http://jqueryui.com/demos/slider/rangemin.html
Only, instead of the range going from the min, going off of where the handle is, and allowing the user to slide either left or right of that fixed starting point to create the range. Any help is appreciated, and I'd be glad to clarify what I need if that doesn't make sense! :)
I'm not sure I understand the question. You want something (what?) to be based on the initial position of the slider "thumb"???

Resources