|
Does this make sense? Shouldn't we just minimize the total amount of bin-space?
|
|
|
|
|
Right,
It has a similar meaning:
"We should maximize the total used amount of bin-space and maximize the used amount of bin-weight-capacity"
|
|
|
|
|
I think your problem is a cross between a few problems:
- it is similar to the knapsack problem with Multiple constraints
https://en.wikipedia.org/wiki/Knapsack_problem[^]
- It is similar to the cutting stock problem with real stock and where the cut don't go back in stock.
And certainly a few others.
What is important is that they are all NP-Hard problems.
Starting from there your optimisation program is more or less a tree exploration program.
On each step, you try to place a packet in the warehouse, if you find a place, go to next packet, otherwise, if you fail to find a place, you backtrack to move previous packet until you success.
To reduce computing time, you sort packets by difficulty to place, starting by the most difficult.
The base of your program will be a recursive tree exploration program.
By the way, your program will fail when a difficult packet comes and the only place is already in use, in this case, you have to backtrack.
Patrice
“Everything should be made as simple as possible, but no simpler.” Albert Einstein
|
|
|
|
|
Strict alternation (using a variable turn that can take the values 0 or 1) can be used to enforce mutual exclusion among two processes p0 and p1.
A. Generalize the idea to get a procedure for mutual exclusion among n processes p0 through
pn−1.
B. Generalize further, to create a procedure for l-exclusion, where n > l ≥ 2.
For both of the above, write suitable pseudocode, and prove if the three desired properties are satisfied with it
|
|
|
|
|
This sounds like homework. Which I am afraid to say that you wont get anyone answering that for you.
People will help you with your homework if you show the work that you have done and give a detailed explanation of what you are expecting the code to do (and not to repeat the homework) and what is happening.
Every day, thousands of innocent plants are killed by vegetarians.
Help end the violence EAT BACON
|
|
|
|
|
It is actually not a homework. I am trying to apply classic distributed algorithms in a peer-to-peer n player mobile game where each player plays only with one of the players who hasn't already lost in an earlier round to another player. A player who has lost waits until last player wins against runner-up , at which time all players are back in game, until then they need play proxy games with any other lost player to improve skills and ranking, but not get any points when the tournament restarts.
When there are is any player playing in tournament, the code looks like this :
for process i
while( 1)
{
while( games[i/2] != 0){}
enter criticalsection and play game;
games[i/2] <- 1; //assign to other player
//after m such rounds, if score of I is > score of I+1, I wins, else I+1 wins. But my challenge is winner set array should be accessible by only one of n processes.
|
|
|
|
|
You could have explained that in the first place in a single question, rather than the three you posted.
|
|
|
|
|
I thought splitting into three discrete smaller problems would help get focused sharper suggestions. Thanks for pointing out
|
|
|
|
|
If it is not homework, it look furiously like it.
Have you done something ? or do you just someone to give you a full functional solution ?
Patrice
“Everything should be made as simple as possible, but no simpler.” Albert Einstein
|
|
|
|
|
A file is to be shared among n different processes, each of which has a unique process ID (a natural number) associated with it. The file can be accessed simultaneously by several processes, subject to the following constraint: if a process with an even process ID is accessing the file, only other processes with even process IDs are permitted to access it; processes with odd IDs are barred, and must wait until all the even-ID processes finish with the file. Similarly, if a process with an odd ID is accessing the file, only other odd-ID processes are permitted to access it, and even-ID processes must wait until all the odd-ID processes finish.
Give pseudocode for a process pi, 0 ≤ i ≤ n − 1.
|
|
|
|
|
Sorry but this site does not provide the answers to your homework questions. You need to show what you have done and where you are stuck.
|
|
|
|
|
It is actually not a homework. I am trying to apply classic distributed algorithms in a peer-to-peer n player mobile game where each player plays only with one of the players who hasn't already lost in an earlier round to another player. A player who has lost waits until last player wins against runner-up , at which time all players are back in game, until then they need play proxy games with any other lost player to improve skills and ranking, but not get any points when the tournament restarts.
When there are is any player playing in tournament, the code looks like this :
for process i
while( 1)
{
while( games[i/2] != 0){}
enter critical section and play game;
games[i/2] <- 1; //assign to other player
//after m such rounds, if score of I is > score of I+1, I wins, else I+1 wins.
Scores for each round in a tournament is stored in a different file for each cycle of tournament and hence I need it to be accessible by only one player - winner or loser( winner is even and loser is assigned odd number and reordered after every round to determine ranking for next tournament round)
|
|
|
|
|
The final sentence in your original post reads:Quote: Give pseudocode for a process pi, 0 ≤ i ≤ n − 1. , which is why it was thought to be a homework question.
|
|
|
|
|
Apologies, I did not know there would be people on this forum scouting for assignment/homework answers. My bad. Hope my thread is not flagged or marked as spam.
Any rough idea/guidance on which I can build will do
|
|
|
|
|
We don't scout for them, but we do read many newly posted questions to see if we can help. And if we find something that looks like the poster has just dumped their assignment expecting to be given a working solution, we explain why it will not happen.
|
|
|
|
|
Can someone show me a framework pseudocode to indicate how a counting semaphore (not a binary semaphore) can be implemented using a Test&Set() hardware primitive?
|
|
|
|
|
Case 1:
Inputs:
[-1, 1, 2, -1, 2, -6, 1, 1, 0, 1, 1, -8]
Ouput:
5
sum of [1, 2, -1, 2] and [1, 1, 0, 1, 1] are 4 which is the max
return 5 as the LENGTH of the maximum contiguous sum
Case 2:
Input:
[-7, -4, -2]
Output:
1
-2 is the maximum contiguous sum
Case 3:
Input: []
Output: 0
|
|
|
|
|
Unclear, and probably homework. Try it yourself; you'll learn something.
|
|
|
|
|
Hi, this questions is similar to this question, but need to return the length. I tried, but still looking for solution
|
|
|
|
|
Member 11875370 wrote: I tried
Describe the algorithm you tried.
|
|
|
|
|
I tried the below code, but just get the max num, to solve the leetcode question. This is the interview question I just faced today.
public int getMaxLen(int[] nums) {
int sum=nums[0];
int max=Integer.MIN_VALUE;
int result = 0;
int cnt = 0;
for(int i=1;i<nums.length;i++){
sum=Math.max(sum+nums[i],nums[i]);
max= Math.max(max, sum);
}
return result;
}
|
|
|
|
|
Right, you'll need to track the "length" as you go, not just the max.
Personally, I would likely define a structure that holds the starting position, the length, and the sum.
I'd fill one with a sequence and then compare with my last known largest one and swap if larger.
modified 30-Jul-15 23:29pm.
|
|
|
|
|
Had you waited a few hours you could have posted this as a Friday Programming Challenge.
modified 31-Jul-15 2:11am.
|
|
|
|
|
I whipped up an implementation in C last night. About an hour's effort.
|
|
|
|
|
Sorry for my English.
_____________________
I can't find an algorithm for this special type of bin packing problem:
____________________
Consider a warehouse with a number of shelves that have number, width, height, depth and limit Weight capacity.
The objects that place in this warehouse are a number of cubes that have number, length, width, height and weight.
The algorithm must find the right place for objects that have the lowest waste of space. and objects weight not be more than shelf weight capacity.
** If a place was assigned to an object, back, front, and on it can not be allocated.
|
|
|
|