optimization

Assigning people to buildings while respecting preferences?

时光总嘲笑我的痴心妄想 提交于 2020-01-12 03:12:40
问题 A friend asked me a question today about an assignment problem. I found a quite straightforward solution, but I feel that it can be made simpler and faster. Your help would be appreciated. The problem: Assuming that I have N people, I need to assign them into M buildings, each building can house K people. Not all people are willing to live with each other, so i have a matrix of N*N cells and a 1 that marks the people that are willing to live with each other. If a cell contains 1 it means that

Launching VS Profiler boosts Application Performance x20?

谁说我不能喝 提交于 2020-01-11 19:42:23
问题 EDIT 1 I do not exclude at all this might be caused by something very basic side effect of using the Profiler (some faulty setting in my "regular" project) I wanted to improve Computing Time in my Application, so I decided to go through a thorough profiling analysis. So I just launched a .Net Memory Allocation Profiling to analyze my App. I was completely stunned to watch computing go x20 times faster ! Application consists of Reading Data from Binary Files with BackgroundWorkers, process

Fastest way to get sorted unique list in python?

自闭症网瘾萝莉.ら 提交于 2020-01-11 17:41:44
问题 What is the fasted way to get a sorted, unique list in python? (I have a list of hashable things, and want to have something I can iterate over - doesn't matter whether the list is modified in place, or I get a new list, or an iterable. In my concrete use case, I'm doing this with a throwaway list, so in place would be more memory efficient.) I've seen solutions like input = [5, 4, 2, 8, 4, 2, 1] sorted(set(input)) but it seems to me that first checking for uniqueness and then sorting is

Fastest way to get sorted unique list in python?

核能气质少年 提交于 2020-01-11 17:41:05
问题 What is the fasted way to get a sorted, unique list in python? (I have a list of hashable things, and want to have something I can iterate over - doesn't matter whether the list is modified in place, or I get a new list, or an iterable. In my concrete use case, I'm doing this with a throwaway list, so in place would be more memory efficient.) I've seen solutions like input = [5, 4, 2, 8, 4, 2, 1] sorted(set(input)) but it seems to me that first checking for uniqueness and then sorting is

Scipy.optimize.minimize objective function ValueError

那年仲夏 提交于 2020-01-11 12:43:08
问题 I am using scipy.optimize.minimize for a small optimization problem with 9 free variables. My objective function is basically a wrapper around another function, and if I evaluate my objective function, the return type is 'numpy.float32'... which is a scalar? However, I am getting the following error when attempting to use the minimize function: raise ValueError("Objective function must return a scalar") ValueError: Objective function must return a scalar Is it not possible to wrap the

Can I `__restrict__ this` somehow?

三世轮回 提交于 2020-01-11 11:34:11
问题 I've been watching Mike Acton's talk on Data-oriented design in C++ in CppCon 2014, and he gives this example: int Foo::Bar(int count) { int value = 0; for (int i = 0; i < count; i++) { if (m_someDataMemberOfFoo) value++ } return value; } And explains how some compilers keep re-reading m_someDataMemberOfFoo in every iteration, perhaps because its value might change due to concurrent access. Regardless of whether it's appropriate for the compiler to do so - can one tell the compiler to

Optimization of greater than operator

ぐ巨炮叔叔 提交于 2020-01-11 11:22:28
问题 credit table and validtransaction table have million record data from year 2008 onwards. We are doing a migration. So I need to find out the credittypeids which are no longer in use after 2017 (periodseq=1055), so that these need not be migrated. This is the query and the >= part is resulting in huge cost. Please suggest an alternative. SELECT CREDITTYPEID FROM CREDITTYPE ct WHERE NOT EXISTS (SELECT 1 FROM CREDIT C WHERE C.PERIODSEQ>=1055 AND C.CREDITTYPEID=CT.CREDITTYPEID ); 回答1: The

Optimization of greater than operator

感情迁移 提交于 2020-01-11 11:21:51
问题 credit table and validtransaction table have million record data from year 2008 onwards. We are doing a migration. So I need to find out the credittypeids which are no longer in use after 2017 (periodseq=1055), so that these need not be migrated. This is the query and the >= part is resulting in huge cost. Please suggest an alternative. SELECT CREDITTYPEID FROM CREDITTYPE ct WHERE NOT EXISTS (SELECT 1 FROM CREDIT C WHERE C.PERIODSEQ>=1055 AND C.CREDITTYPEID=CT.CREDITTYPEID ); 回答1: The

Lengthy perl regex

左心房为你撑大大i 提交于 2020-01-11 11:19:13
问题 This may seem as somewhat odd question, but anyhow to the point; I have a string that I need to search for many many possible character occurrences in several combinations (so character classes are out of question), so what would be the most efficent way to do this? I was thinking either stack it into one regex: if ($txt =~ /^(?:really |really |long | regex here)$/){} or using several 'smaller' comparisons, but I'd assume this won't be very efficent: if ($txt =~ /^regex1$/ || $txt =~ /^regex2

R: Error in is.nloptr(ret) : objective in x0 returns NA

限于喜欢 提交于 2020-01-11 10:49:49
问题 I am trying to use the nloptr package to find the optimal x value that maximized the non-linear function F=b0+b1*x+b2*x^2+b3*x^3. I am using the following code with apply() function in order to loop it through each individual row of the Regression data frame and get the optimal value of the function for each individual row: F <- function(x,b0,b1,b2,b3){return(b0+b1*x+b2*x^2+b3*x^3)} Optimal <- apply(Regression,1,function(i){ nloptr( x0 <- c(0) ,eval_f <- F ,eval_g_ineq = NULL ,eval_g_eq =