effective calculate method for RCPSP(resource constrained project scheduling problem) - c++

The problem I am solving is scheduling tasks from limited resources.
The way I thought about it is to use a two-dimensional array to identify resources.
I wonder how I can calculate efficiently because the operation speed is too long.
Using a binary tree is likely to be difficult. After calculation, there is a process of randomly exchanging indexes for the search process.
For example)
Factory's capacity : 4
A(2,2) B(3,2) C(1,1) \\\\task(processing time , required area)
Schedule : A-B-C ,1 means that there is space left, and 0 means that there is no space.
A task can only be allocated if the space required is continuously present.
The x-axis represents time and the y-axis represents capacity.
1 1 1 ... ㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡ 1 1 1 ㅡㅡㅡㅡㅡㅡㅡ 0 0 0 1 ㅡㅡㅡㅡㅡ 0 0 0 1
1 1 1 ... ㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡ 1 1 1 ㅡㅡㅡㅡㅡㅡㅡ 0 0 0 1 ㅡㅡㅡㅡㅡ 0 0 0 1
1 1 1 ... ㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡ 0 0 1 ㅡㅡㅡㅡㅡㅡㅡ 0 0 1 1 ㅡㅡㅡㅡㅡ 0 0 1 1
1 1 1 ... ㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡ 0 0 1 ㅡㅡㅡㅡㅡㅡㅡ 0 0 1 1 ㅡㅡㅡㅡㅡ 0 0 0 1

The good new is your problem looks very similar to well known Job shop scheduling problem. The bad new is Job shop scheduling is NP-hard.

Related

How to add bins created by xtabs with zero values

I'm creating frequency tables of my data to then compare. however, further comparisons are not possible because my frequencies created by Xtabs are resulting in different lengths. How do I force a specified length on Xtabs that will fill in the missing bins with zeros rather than leave them out. For example, using xtabs(~lcat20+AgeBin1, data = datasource), my result was:
AgeBin1
lcat20 0 1 2 3 4
100 1 0 0 0 0
160 5 1 0 0 0
180 2 3 0 0 0
200 1 2 0 0 0
lcat20=120 and lcat20=140 are missing because that dataset does not have any samples in those sizes. How do I fill in these missing categories? I appreciate any help.

J how to make a shape of random numbers

I'm trying to make a shape of random numbers (0 or 1) in this case as I'm trying to create a minesweeper field.
I've tried using the "?" symbol for random to receive it but it normally turns into an unrandom, repeated pattern which for my purposes is unsatisfactory:
5 5 $ ? 0 1
0 1 0 1 0
1 0 1 0 1
0 1 0 1 0
1 0 1 0 1
0 1 0 1 0
Because of this, I tried other ways like pulling numbers from an index (this is called roll). But this returns random decimals. Other small changes to the code also resulted in these random decimals.
I've done this a few times myself. The key thing is when you apply the ?. You get the result that you want if you apply it after the matrix has been created.
We know that ?2 returns a 1 or a 0 value generated randomly.
? 2
0
? 2
1
? 2
0
So if we create a 5X5 matrix of 2's
5 5 $ 2
2 2 2 2 2
2 2 2 2 2
2 2 2 2 2
2 2 2 2 2
2 2 2 2 2
then we apply ? to each 2 in the matrix you get the random 1 or 0 for each position.
? 5 5 $ 2 NB. first 5 X 5 matrix of random 1's and 0's
0 0 0 1 1
1 1 1 0 1
0 0 0 0 1
1 1 1 1 0
1 1 1 0 0
? 5 5 $ 2 NB. different 5 X 5 matrix of random 1's and 0's
0 0 0 1 1
1 0 1 1 0
0 0 0 1 1
1 0 0 1 0
1 1 1 0 0

The longest cycle in an undirected graph

How i can get the longest cycle in a undirected Graph (without BackTracking, it takes too long).
Example:
0 3 0 1 0
3 0 0 1 0
0 0 0 0 0
1 1 0 0 0
0 0 0 0 0
Solve: 3 + 3 + 1 => Out: 1 - 2 - 3 - 1.
If you can find the longest cycle, you can detect whether the graph has a Hamiltonian Cycle, which is an NP-complete problem, thus making your problem NP-hard.
That means no solution will be fundamentally better than backtracking unless P=NP.

How to rearrange vector to be cols not rows?

I am solving systems of equations using Armadillo. I make a matrix from one array of doubles, specifying the rows and columns. The problem is that it doesn't read it the way I make the array, (it's a vector but then converted to an array) so I need to manipulate the vector.
To be clear, it takes a vector with these values:
2 0 0 0 2 1 1 1 0 1 1 0 3 0 0 1 1 1 1 0 0 1 0 1 2
And it makes this matrix:
2 1 1 1 0
0 1 0 1 1
0 1 3 1 0
0 0 0 1 1
2 1 0 0 2
But I want this matrix:
2 0 0 0 2
1 1 1 0 1
1 0 3 0 0
1 1 1 1 0
0 1 0 1 2
How do I manipulate my vector to make it like this?
I feel as if you are looking for a transposition of a matrix. There is relevant documentation here.

iterate through a 3d matrix, finding all solutions

iterate through a 3d matrix
i need to check every possible solution to a certain predicament.
i have a matrix[x][y][z] that represents possible nodes to travel through. I already finished a method that should give me a set of solutions (it disables a single path every iteration and recalculates the entire solution, disable priority is based on travel capacity of the last solution)
but i need to see how effective my method is in terms of total time taken to calculate a set. For this i require a method calculate the solution on every permutation of these paths.
currently it only has a single layer in between 2 main layers (L1) where 0 is a free path and 1 is a non accessible path.
This here is the starting layout where i can toggle the values on layer L1 from 0 to 1 to disable a path and the basis of my shortest path search algorithm.
L0 0 0 0 0 0 L1 0 1 0 1 0 L2 0 0 0 0 0
0 1 0 1 0 1 1 1 1 1 0 1 0 1 0
0 0 0 0 0 0 1 0 1 0 0 0 0 0 0
0 1 0 1 0 1 1 1 1 1 0 1 0 1 0
0 0 0 0 0 0 1 0 1 0 0 0 0 0 0
how can i iterate through every possible combination of disabling the free paths when the dimensions of the matrix are non constant (meaning they are already user defined on compile time and can be changed whenever)? there are 2^n solutions where n is the number of free path on all mediary layers.
(a quick explanation in C or C++ would be best, even pseudo code is good) since there currently 9 free path to make combinations with there should be about 2^9 solutions which i need to test with. I havent done any brute force algorithms before so i have no idea how to make one.