optimization

Priority Queue with a find function - Fastest Implementation

断了今生、忘了曾经 提交于 2020-06-09 17:00:09
问题 I am looking at implementing a priority queue with an added requirement, a find/search function which will tell whether an item is anywhere within the queue. So the functions will be: insert, del-min and find. I am unsure whether I should use a Heap or a Self-balancing binary search tree. It appears PQs are usually implemented with a Heap, but I am wondering if there is any advantage in using a binary search tree since I also need that find function. Furthermore, on average I'll be doing more

Priority Queue with a find function - Fastest Implementation

无人久伴 提交于 2020-06-09 16:59:10
问题 I am looking at implementing a priority queue with an added requirement, a find/search function which will tell whether an item is anywhere within the queue. So the functions will be: insert, del-min and find. I am unsure whether I should use a Heap or a Self-balancing binary search tree. It appears PQs are usually implemented with a Heap, but I am wondering if there is any advantage in using a binary search tree since I also need that find function. Furthermore, on average I'll be doing more

How To Reduce Python Script Memory Usage

戏子无情 提交于 2020-06-09 07:31:09
问题 I have a very large python script, 200K, that I would like to use as little memory as possible. It looks something like: # a lot of data structures r = [34, 78, 43, 12, 99] # a lot of functions that I use all the time def func1(word): return len(word) + 2 # a lot of functions that I rarely use def func1(word): return len(word) + 2 # my main loop while 1: # lots of code # calls functions If I put the functions that I rarely use in a module, and import them dynamically only if necessary, I can

Putting integer constraints in mystic

删除回忆录丶 提交于 2020-06-09 05:32:06
问题 I am new to mystic and working on an optimization problem.My mystic code looks like this: def find_loss(e,lmd,q,k): edge_pmf=find_final_dist(e,lmd,q) l_e=sum(edge_pmf[k+1:]) return l_e def objective(x): s=0 for i in range(len(x)): s+=find_loss(edge_enum[i],lamd,q,x[i]) return s added=lambda x: [i for i in x] cons=lambda x: my.constraints.impose_sum(total_cap,added(x)) @integers() def round(x): return x bounds=[(0,None)]*a if __name__=='_main_': result=diffev2(objective,x0=bounds,bounds=bounds

Trying to grasp the point of putting frames and widgets in classes for tkinter

允我心安 提交于 2020-06-08 15:06:21
问题 As the question states, I can't seem to fully grasp the point of using classes with tkinter. I have read through a decent number of different sites but I keep getting search results on how to create and use classes, but none so far have been able to get through to me. I've even scoured through the suggested questions while asking this one. The closest I've come to understanding is Bryan's explanation on this answer to the question Why use classes when programming a tkinter gui? But still, I

Match lists and get value of one column based on values of other columns from dataframe optimization

帅比萌擦擦* 提交于 2020-06-05 09:02:32
问题 I have an input dataframe like below, where 'ID' is unique identifier, 'Signals_in_Group' is a derived field containing list of all unique 'Signal' column values present in a 'Group'. And 'Signals_Count' is also a derived field whose values are count of items in 'Signals_in_Group'. groups_df ID Timestamp Signal Group Signals_in_Group Signals_Count 1 5 1590662170 A 1 [A, B, C] 3 2 2 1590662169 B 1 [A, B, C] 3 3 6 1590662169 C 1 [A, B, C] 3 4 8 1590662171 D 2 [A, D] 2 5 7 1590662172 A 2 [A, D]

How to temporarily disable Django indexes (for SQLite)

北战南征 提交于 2020-06-01 07:00:09
问题 I'm trying to create a large SQLite database from around 500 smaller databases (each 50-200MB) to put into Django, and would like to speed up this process. I'm doing this via a custom command. This answer helped me a lot, in reducing the speed to around a minute each in processing a smaller database. However it's still quite a long time. The one thing I haven't done in that answer is to disable database indexing in Django and re-create them. I think this matters for me as my database has few

R optimisation buy sell

戏子无情 提交于 2020-06-01 05:55:19
问题 I need to find a solution to an optimisation problem. In my simplified example, I have a prediction of prices for the next year. I have inventory that can contain max 25 products. I can either sell or buy each month. I cannot buy more than 4 products or sell more than 8 products per month. I am looking for profit by buying for lower price than selling. Is there a package/function that can indicate when to buy and when to sell? The objective is to maximise the profit at the end of the period

R optimisation buy sell

社会主义新天地 提交于 2020-06-01 05:54:13
问题 I need to find a solution to an optimisation problem. In my simplified example, I have a prediction of prices for the next year. I have inventory that can contain max 25 products. I can either sell or buy each month. I cannot buy more than 4 products or sell more than 8 products per month. I am looking for profit by buying for lower price than selling. Is there a package/function that can indicate when to buy and when to sell? The objective is to maximise the profit at the end of the period

R optimisation max buy/sell dependent on stock level

风格不统一 提交于 2020-06-01 05:03:50
问题 I would like to find a solution to an optimisation problem. The aim is to maximise profit by buying for low price and selling for a higher one. There are constraints such as maximum stock level, and max buy/sell number of units. Moreover, sell and buy limits depend on the inventory levels. I have asked a similar question albeit without the last condition here R optimisation buy sell. Here is an example: price = c(12, 11, 12, 13, 16, 17, 18, 17, 18, 16, 17, 13) capacity = 25 max_units_buy_30 =