Capacitated Slugging Dynamic Programming
Def 1: A slugging graph G = (V, E), is a directed acyclic graph where V = {T1, T2, ..., Tm} is a set of trips and E is a set of directed edges between nodes that is transitive, i.e. if (Ti, Tj) in E and (Tj, Tk) in E, then (Ti, Tk) in E.
Def 2: Given a slugging graph G = (V, E), a slugging plan Gs = (V, Es), Es in E, is a subgraph of G that satisfies the following conditions: (i) For all (Ti, Tj) in Es, there is no k != j such that (Ti, Tk) in Es; (ii) For all (Ti, Tj) in Es, there does not exist k suck that (Tk, Ti) in Es.
Basically, (i) says that Ti can be merged into at most 1 other trip and (ii) says that Ti can be merged into another trip if and only if there is no other Tk that has been merged into Ti.
Def 3: Given a slugging graph G = (V, E), a benefit is a value associated with each edge (Ti, Tj) in E. The value of benefit is given by function B(Ti, Tj) in R+. The value of B depends only on the sorce edge, i.e. B(Ti, Tj) = B(Ti, Tk) = B(Ti, Tm) and so on and so forth.
Def 4: Total benefit is the summation of B(Ti, Tj) in the slugging plan Gs = (V, Es), i.e. (Ti, Tj) in Es, B(Gs).
Def 5: Each trip Ti has number of passengers and number of available seats. If Ti is merged into Tj, passengers of Ti occupy some available seats of Tj. Number of available seats of Tj decreases so. If Ti has more passengers than available seats in Tj, Ti cannot be merged into Tj and, therefore, there is no (Ti, Tj) in Es.
Problem: Given a slugging graph G = (V, E) and definitions 15, find a slugging plan Gs = (V, Es), Es in E, that has maximal total benefit B(Gs).
For a detailed description of the problem, visit this link and see subsection 3.3.
I have to solve this problem using Dynamic Programming. It seems to me related to 01 Knapsack to some extent. For example, deciding whether or not to merge Ta, Tb and Tc into Tj is similar to having objects a, b and c and try to fit then into a bag j in a way the profit is maximum and bag capacity is preserved. However, Ta, Tb and Tc may become a bag rather than an object in this problem. Based on that, I have not been able to find the optimal substructure to start thinking about Dynamic Programming details. Could anyone lend me a hand on this?
See also questions close to this topic

Why tensorflow's implementation of AdamOptimizer does not support L2 normalization
Tensorflow's implementation of AdamOptimzer do not have regularization params like that in ProximalAdamOptimizer, for example
l2_regularization_strength
, is it necessary to add l2 norm in AdamOptimzer? 
Excel VBA  Optimizing Code
I'm trying to optimize some VBA that I put together. I know that using
Select
a lot slows down performance quite a bit so I've been trying to cut that out where I can. Is there anything else in my code that I can change or do differently to improve performance? Thank you in advance!Sub PP_Formatting_Saving() Application.ScreenUpdating = False 'Ungroups sheets by selecting Wksht 2 Worksheets(2).Select 'Input 1 into Cell AK1 then Multiply columns to convert to number Range("AK1").Value = "1" Range("AK1").Copy Range("N" & Rows.Count).End(xlUp).Select Range(Selection, Selection.End(xlUp)).Select Selection.PasteSpecial Paste:=xlPasteAll, Operation:=xlMultiply, _ SkipBlanks:=False, Transpose:=False Range("AA" & Rows.Count).End(xlUp).Select Range(Selection, Selection.End(xlUp)).Select Selection.PasteSpecial Paste:=xlPasteAll, Operation:=xlMultiply, _ SkipBlanks:=False, Transpose:=False Range("G" & Rows.Count).End(xlUp).Select Range(Selection, Selection.End(xlUp)).Select Selection.PasteSpecial Paste:=xlPasteAll, Operation:=xlMultiply, _ SkipBlanks:=False, Transpose:=False Range("AK1").ClearContents 'Format Amount as Accounting Range("J" & Rows.Count).End(xlUp).Select Range(Selection, Selection.End(xlUp)).Select Selection.Style = "Comma" 'Format header color & bold Range("A1").Select Range(Selection, Selection.End(xlToRight)).Select With Selection.Interior .Pattern = xlSolid .PatternColorIndex = xlAutomatic .Color = 12632256 .TintAndShade = 0 .PatternTintAndShade = 0 End With Selection.Font.Bold = True 'Autofit all columns Cells.Select Cells.EntireColumn.AutoFit Columns("O:O").ColumnWidth = 40 'Filter all headers Selection.AutoFilter 'Unwrap Text in sheet 1 Worksheets(1).Select Cells.Select With Selection .WrapText = False End With 'Format Amount as Accounting Range("C" & Rows.Count).End(xlUp).Select Range(Selection, Selection.End(xlUp)).Select Selection.Style = "Comma" 'Input 1 into Cell AK then Multiply columns to convert to number Range("AK1").Value = "1" Range("AK1").Copy Range("B" & Rows.Count).End(xlUp).Select Range(Selection, Selection.End(xlUp)).Select Selection.PasteSpecial Paste:=xlPasteAll, Operation:=xlMultiply, _ SkipBlanks:=False, Transpose:=False 'Autofit all columns Cells.Select Cells.EntireColumn.AutoFit 'Format header color & bold Range("A1").Select Range(Selection, Selection.End(xlToRight)).Select With Selection.Interior .Pattern = xlSolid .PatternColorIndex = xlAutomatic .Color = 12632256 .TintAndShade = 0 .PatternTintAndShade = 0 End With Selection.Font.Bold = True 'Filter all headers Selection.AutoFilter Dim ws As Worksheet Dim wbNew As Workbook 'Select PP sheet, filter all cells on Variable1 in Column 31. Copy all of that then paste in new sheet, rename sheet as PP1. UsedRange selects all cells with value in it Sheets("PP").Select ActiveSheet.UsedRange.AutoFilter Field:=31, Criteria1:= _ "Variable1" Cells.Select Range("Y1005").Activate Selection.Copy Sheets.Add After:=ActiveSheet ActiveSheet.Paste ActiveSheet.Name = "PP1" 'Select BK sheet, filter all cells on Variable2 in Column 16. Copy all of that then paste to new sheet, rename as BK1. UsedRange selects all values in worksheet. Sheets("Bk").Select ActiveSheet.UsedRange.AutoFilter Field:=16, Criteria1:= _ "Variable2" Cells.Select Range("O15").Activate Application.CutCopyMode = False Selection.Copy Sheets.Add After:=ActiveSheet ActiveSheet.Paste ActiveSheet.Name = "BK1" 'Copy BK & PP in Array then save as new workbook Worksheets(Array("BK", "PP")).Copy Set wbNew = ActiveWorkbook 'Naming the workbook w/ date format wbNam = "BK_PP_" dt = Format(DateAdd("m", 1, Now), "yyyy_mm") 'Save location ActiveWorkbook.SaveAs "\\user\location\" & wbNam & dt & ".xlsx" 'Close new workbook that just saved ActiveWorkbook.Close 'Delete sheets created in original workbook Sheets("PP1").Delete Sheets("BK1").Delete

Web GL. Slow render with texture change
I'm using empscripten. After several tests, I came to the conclusion that if I draw 500 identical textures, everything works fine. But if I draw 2 different textures 500 times, I get a big load on CPU. 14 against 60% on the osx. In windows, almost the same problem (6 vs 16%), only the difference is small. both textures have a size of 2x2 pixels.
Can I somehow optimize this?

Ride Scheduling , using dynamic programming
You arrive at Waldo's World Amusement Park with T minutes remaining until the park closes. The park has n rides and your objective is to complete as many rides as possible before the park closes. (For this problem, taking the same ride twice counts as 2 rides.) You are given a table W such that W(i, t) gives you the waiting time for ride i at time t. For convenience, assume that t is expressed as minutes before the park closes. Ride i itself takes ri minutes and all times are measured in integer minutes.
I know this question was somewhat answered in this post: Amusement Part Scheduling Algorithm
, but the explanation was somewhat vague and I was wondering if anyone could provide further clarity on this solution or any other solution?

Fastest way to calculate skeleton of image in C++
I am using OpenCV (C++) and want to find the skeleton of an image in the fastest way.
The input image
hand_bw
is:As of now, this is what I have:
cv::Mat skel(hand_bw.size(), CV_8UC1, cv::Scalar(0)); cv::Mat temp(hand_bw.size(), CV_8UC1); cv::Mat element = cv::getStructuringElement(cv::MORPH_ELLIPSE, cv::Size(3, 3)); bool done; int i = 0; do { cv::morphologyEx(hand_bw, temp, cv::MORPH_OPEN, element); cv::bitwise_not(temp, temp); cv::bitwise_and(hand_bw, temp, temp); cv::bitwise_or(skel, temp, skel); cv::erode(hand_bw, hand_bw, element); double max; cv::minMaxLoc(hand_bw, 0, &max); done = (max == 0); i = i+1; } while (!done); cv::imshow("Skeleton", skel);
The corresponding output is:
What is the fastest way to achieve this result in C++ (probably Dynamic programming)? Time is my major constraint.

Min ED without modify function
I have a set of rules which allow me to change one string into another.
Those rules are:
aaa>aa
abaac>abac
a>baabaabaa
So let's say I have string
R
which is original (target string) and stringQ
which I want to modify using above rules to match some substring of original stringR
.A special condition for all rules is that once I use a letter in one rule, it can not be used in another rule anymore at all. Same applies for newly generated letter by those rules. (See rule 3., where I have
a
and I createbaabaabaa
. I can't usebaabaabaa
anymore.)Example for using rules: (ignore spaces between letters)
abac aaa bb abaac b > abac aa bb abac b .....R1.....R2..... > .....R1....R2.... abaa aaa > abaa aa .....R1. > .....R1
As this second example
abaaaaa
shows, I generateaa
fromaaa
and that will give meabaaaa
but since I have generated last twoaa
I can not use R1 anymore because I have left only twoaa
which weren't used in R1. I could use R3 twice in this case, for eacha
once.Another example where I use R1 twice:
accbaaabccaaa > accbaabccaa ....R1....R1. > ....R1...R1
I have been thinking how can I write an algorithm using edit distance to find a starting position of string
Q
in stringR
, where forQ
I can use those rules to "edit it". What would be the best thing do?Example of input and output:
R = abaaacbaab
Q = abaaaa
Output:
0,1
Since starting position of "modified Q" starts on position 0 in stringR
and total number of used rules to "modify(insert/delete)" Q into some substring in R is one (rule 1. used).This problem is for dynamic programming so I have been thinking about two arrays, array for Q and other for R instead of remembering all rows and columns, because that would take a lot of memory. Problem is, I don't know how exactly should I solve this problem, use only insert and delete functions? If yes, how can I apply those rules into it?
 prove that for all Y ∈ NP, the complementary Y' is also in NP

Is it decidable to detect a virus?
I have been reading Cohen's dissertation (1985) and much to my dismay, have to present an antithesis. I don't even know how to, or where to begin since the answer in this case doesn't lie in the contradiction of the Halting Problem, and I cannot refute the Halting Problem in itself. What methods should I take to tackle this research question? Are there any papers I can read? Are there any key points that I can further elaborate on?

Topological sorting and NPhard proof
I meet a problem. I can find a suboptimal solution, but cannot find an optimal one and cannot prove its NPC hardness. The problem can also be described as follows. Given a sequence X={x1,x2,...,xn},a set of partial orders P(<), where xi < xj means that xi must be in front of xj, and a new item xk as well as related orders xk < xi for some i's and xj < xk for some j's, how to find the least replacement solution to insert xk into the original sequence X without violating these partial orders? It can be ensured that these partial orders form no cycle such as xi < ... < xj < ... < xi.

Algorithm for the distance among nearest vectors
Given n vectors of dimension m. For every vector, each dimension can be replaced by the other dimension value of this vector, and each value can only be used only one time to replace the other dimension. After the changing of all these n vectors, we calculate the Manhattan distance between each vector and its nearest vector. For all the replacing plans, we select the one which can get the minimum sum of the distance between all these n vectors and these nearest vectors. Is it NPhard?

Finding Solution for an timetable maker
Hello im actually working on a timetable maker and cant think of an satisfiable solution, as this is probably an NPComplete problem. What i want to create specifically is a tool, to help planing workinggroups of the serveral subjects on university.
Lets get into that a little bit more in detail: 4 instances are given:
1.Subjects: There exists a list of subjects (maths, programming, algorithms) etc. Each subject contains a list of students who are participating on the lecture.
2.Timeslots: A List of timeslots is given, in which we can assign workinggroups to. (Like Monday 1. lesson) Multiple workinggroups (also from the same subject) can be assigned to the same timeslot.
3.workinggroups: We assign students into workinggroups. A group is related to an subject and has a minimum and maximum size.
 Students: Are the students we assign to an group. Each student has preferences according to timeslots and students, they want to be in a group with. There are timeslots which students prefer, cant be assigned to (e.g because they are in another working group at that time, or other reasons), or dont care about.
The task would be to find an optimal solution.
But before I would attack the optimal solution, I at least like to find a feasible solution. The hard constraints i would like to meet is:
that every student gets a place in an workinggroup, of the subject he is assigned to, without conflict. So that his workinggroups dont run at the same timeslot.
might be similar to nr.1 but: that the student wont be assigned to the timeslots which the student has marked as "cant be assigned to"
that the group size boundaries are not violated.
There are actually just 2 solutions that come to my mind. 1.Allocating the groups randomly and than switching groups between timeslots  and switching students between groups randomly until a feasible solution was created (could take forever) 2.or instead of switching the objects randomly, use something like backtracking.
But also backtracking can take a hell of time. Considering all the possibilities that can be created given the task. With lets say 60 students, i'm not sure if thats a acceptable solution.
What do you think of that problem?

How does NPHard is different from NP?
I understand the set definitions of NP, NPcomplete and NPhard. I understand that if we can solve an NPcomplete problem, we can solve all NP problems. I also know that a problem is classified as NPhard if an NPcomplete problem is reducible to it in polynomial time. I know the definitions, but I am unable to understand how NPHard problems are different than NP.
My question is what quality classify a problem not in NP but in NPHard (if there is a quality other than the reducibility assumption)? Also, which time complexities classify a problem in NP and which do in NPHard (if there is a clear distinction)? Shortly, what classifies a nondeterministic polynomial time complexity as hard?
Edit: I already read the question marked as a duplicate prior to writing this, so maybe I need to explain more... For example, an NPHard problem does not have to be in NP or does not have to be decidable either. However, these are just possibilities and does not have to apply to all of the NPHard problems. So maybe I should ask, is there a quality other than reducibility that does apply to all NPHard problems to distinguish them from NP problems?