Multithreaded Shortest Job First Scheduling Algorithm - multithreading

I'm familiar with Shortest Process next Scheduling Algorithm (SJF) which is a non preemptive algorithm. But, this algorithm handles only one process at a time which has the smallest burst time. Can it be modified as Shortest Process Next 2 at a time?
So for the example mentioned here:
5
A 0 3
B 2 6
C 4 4
D 6 5
E 8 2
The first lines denotes the Total number of processes.
The subsequent lines denotes the Process ID, Arrival Time, Burst Time.
The SJF scheduling with 2 processes at a time will works as follows :
Time | A | B | C | D | E | IDLE |
------------------------------------------------
0 | O | | | | | 1 |
1 | O | | | | | 1 |
2 | X | O | | | | |
3 | | O | | | | 1 |
4 | | O | O | | | |
5 | | O | O | | | |
6 | | O | O | | | |
7 | | X | X | | | |
8 | | | | O | O | |
9 | | | | O | X | |
10 | | | | O | | 1 |
11 | | | | O | | 1 |
12 | | | | X | | 1 |
Here,
O: Process scheduled
X: Process completed
Idle denotes how many processors are currently idle. For this case, there are 2 processors.
It can be observed that at time t=4, there are 2 processes scheduled instead of 1.

Why not use a rb-tree and add the tasks to the tree based on their burst time?
The tasks with the least amount of burst time (shortest job) is the left most node in the tree. So when you pick your next tasks, you just remove the left most node from the tree.
When the task completes, you take next task from the rb queue.
When the task blocks, you put it on a separate structure and you take the next task from the tree. You also update the burst time. Once it unblocks, you reinsert it back into the rb-tree.
When a task yields, you update the burst time and reinsert it back into the rb-tree and then take the next task from the tree.
And you can have multiple processors taking tasks from the rb-tree and each will pick the one with the lowest burst time.
The Linux CFS uses a similar mechanism.

Related

Grouping a list of items in to as equal in numbers as possible

Requirement: Split a list in to 4 separate groups, based on a value for each row.
| Player | Skill |
| ------------- |:-------------:|
| Player 1 | 10000 |
| Player 2 | 50000 |
| Player 3 | 2000 |
| Player 4 | 11000 |
| Player 5 | 7525 |
| Player 6 | 100 |
| Player 7 | 999 |
| Player 8 | 14579 |
| Player 9 | 26700 |
So in the example above, these players would be split in to 4 groups:
| Group | # of players |
| ------------- |:-------------:|
| Group1 | 2 |
| Group2 | 2 |
| Group3 | 2 |
| Group4 | 3 |
The number of players in a group needs to be as close as possible, however, as a group, the groups total Skill needs to around similar in numbers each time.
Before I go too far down the rabbit hole (as wording a question like this in a simple google search is not turning out very well) are there any built in functions of Excel that can be leveraged to achieve this or possible efforts in VBA that can be explored to achieve the required result?
This isn't an answer! But suppose you try a simple algorithm:
Calculate average skill level (ASL) for all 9 players
Set TSG (total skill for group) to zero.
Loop:Take largest skill Level (LSL) of remaining players
If TSG+LSL>ASL
Go to next group
Else
Add to total skill (TSG) for this group
Remove player from list
Repeat loop until no players remaining.
If you apply this by hand to your data you should get:
Average=30725.75
+---------+---------+---------+---------+
| Group 1 | Group 2 | Group 3 | Group 4 |
+---------+---------+---------+---------+
| 50000 | 26700 | 14579 | 10000 |
| | 2000 | 11000 | 7525 |
| | 999 | | |
| | 100 | | |
| | | | |
| 50000 | 29799 | 25579 | 17525 |
+---------+---------+---------+---------+
Clearly there are a couple of issues - you might not want a single group containing only player with highest skill level. Also you might want to re-average the remaining players after taking out the most skilful player. Should be a starting point though - could be implemented fairly easily with formulas or VBA.

Spotfire how to make calculation along one coloumn

I have a data table as below.I would like to create a new column called "Time Difference" which captures the time difference between [STAGE] start and [STAGE] end. Is there any way to do it without using data transformation?
Thank you!
Assuming each ID is unique, and your data is ordered by Time where Stage = Start is the first row for each ID and Stage = End is the last row for each ID, you can use this:
Concatenate(Min([Time]) OVER ([ID]),"-",Max([Time]) over ([ID]))
RESULTS
+----+---------+---------+------+-----------------+
| ID | Stage | Action | Time | Time Difference |
+----+---------+---------+------+-----------------+
| 1 | Start | approve | A | A-F |
| 1 | Process | approve | B | A-F |
| 1 | Process | approve | C | A-F |
| 1 | Process | approve | D | A-F |
| 1 | Process | decline | E | A-F |
| 1 | End | approve | F | A-F |
| 2 | Start | approve | G | G-I |
| 2 | Process | decline | H | G-I |
| 2 | End | approve | I | G-I |
+----+---------+---------+------+-----------------+
If your data isn't already sorted, you can just apply a Rank() to fix this. Let me know if that's the case.
EDIT WITH NEW DATA
EXPRESSION
Concatenate(Min(If((Upper([Stage])="START") and (Upper([Action])="APPROVE"),Max([Time]) OVER ([ID]))) OVER ([ID]),"-",Min(If((Upper([Stage])="END") and (Upper([Action])="APPROVE"),Max([Time]) OVER ([ID]))) OVER ([ID]))
Simplified
Concatenate(Min(If((Upper([Stage])="START") and (Upper([Action])="APPROVE"),[Time])) OVER ([ID]),"-",Min(If((Upper([Stage])="END") and (Upper([Action])="APPROVE"),[Time])) OVER ([ID]))
RESULTS
+----+---------+---------+------+-----------------+
| ID | Stage | Action | Time | Time Difference |
+----+---------+---------+------+-----------------+
| 1 | On hold | decline | A | C-H |
| 1 | Start | decline | B | C-H |
| 1 | Start | approve | C | C-H |
| 1 | Process | DECLINE | D | C-H |
| 1 | Process | approve | E | C-H |
| 1 | Process | approve | F | C-H |
| 1 | End | decline | G | C-H |
| 1 | End | approve | H | C-H |
| 2 | Start | approve | I | I-K |
| 2 | Process | decline | J | I-K |
| 2 | End | approve | K | I-K |
+----+---------+---------+------+-----------------+

values of new table changing dynamically with the input of the initial table

I have a question in Excel and need your help!
I can do this if it was static problem but I need my end result to adjust to my input in the table because the year sometimes the year finishes sooner or later or is different or the number of activities vary.
Initial table (It always go in chronological order and it only has 1 or nothing. (I put 0 there because I wanted to put space and didn't know how to do it. also Number of activities may vary)
+----------------+------+------+------+------+------+------+
| year | 2016 | 2016 | 2016 | 2017 | 2017 | 2017 |
+----------------+------+------+------+------+------+------+
| month calendar | 10 | 11 | 12 | 1 | 2 | 3 |
| month project | 1 | 2 | 3 | 4 | 5 | 6 |
| Activity 1 | 1 | 1 | 0 | 0 | 0 | 0 |
| Activity 2 | 0 | 0 | 1 | 1 | 1 | 1 |
| Activity 3 | 0 | 0 | 0 | 1 | 1 | 0 |
| Activity 4 | 0 | 1 | 1 | 0 | 0 | 0 |
| Activity 5 | 1 | 1 | 1 | 1 | 1 | 1 |
+----------------+------+------+------+------+------+------+
I want in another sheet
+---------------+------------+------------+------------+------------+
| Activity year | 2016 | | | |
| | | | | |
| Activity 1 | Activity 2 | Activity 3 | Activity 4 | Activity 5 |
| 25,0% | 12,5% | 0,0% | 25,0% | 37,5% |
| | | | | |
| Activity year | 2017 | | | |
| | | | | |
| Activity 1 | Activity 2 | Activity 3 | Activity 4 | Activity 5 |
| 0,0% | 37,5% | 25,0% | 0,0% | 37,5% |
+---------------+------------+------------+------------+------------+
Now imagine that in the "another sheet" I have nothing and I want the result to adjust to the initial table. How can I do this?
Sorry for bad editing but I can't do better.
Any help is good thank you, I answer any question you might have.
I'm going to add something that is related to this and I also need. I need a formula to get the number of different activities per year that happen at least once for my calculations later. In this case it would be a formula for 2016 which the result is 4 and 2017 is 3.

Excel 2010 Calculating Production line quantities without long calculations

Program: Excel 2010
Requirements: Prefer no VBA (Macro free book)
I am creating a spreadsheet to calculate items required for components (parts). I have a list of the product, and under the number of specific parts. I have a calculation which tells me what the total parts are needed, but, is there a better way?
=($C$32*C34)+($D$32*D34)+($E$32*E34)+($F$32*F34)+($G$32*G34)+($H$32*H34)+($I$32*I34)+($J$32*J34)+($K$32*K34)
| A | B | C | D | E | F |
| Making: | | 2 | 2 | 2 | |
|---------------|-------|------------|-------------|-----------------|---------|
| Item -> | Total | Small raft | Rowing boat | Sm sailing boat | Corbita |
| | | | | | |
| Planks | 20 | 4 | 6 | | |
| Logs | 8 | 4 | | | |
| Nails - Large | 16 | 8 | | | |
| Oars | | | | | |
In the above, you can see that ($C$32*C34) = 8 & ($D$32*D34) = 12 => 12+8 = 20 (B34) (Planks Total)
Is there an easier way of doing this, or will my equation just keep getting bigger?
Thanks in advance.
As chris neilsen mentioned in his comment, you can use the SUMPRODUCT function in Excel. The formula in your cell B34 (total planks) should look like this:
=SUMPRODUCT(C32:K32,C34:K34)
This has the effect of multiplying the corresponding components in the given ranges (C32 * C34, D32 * D34, etc.) and then returning the sum of those products/multiplications.
As you add more columns, you can expand K to the last column in the range that you want to add up in both ranges.

Transform values without VBA but with Index and Match

I'm trying to find a solution without macros in excel for following problem:
There is a table containing ratings of a student for different time periods.
So the rating of the student with ID=1 was 1 from January to April and 3 from Mai to June.
Two other students had a constant ranking (6 and 9) from January to June
| A | B | C |D |
---| ----|------------|------------|-------|
1 | ID | START | END |RANKING|
2 | 1 | 01.01.2014 | 30.04.2014 | 1 |
3 | 1 | 01.05.2014 | 30.06.2014 | 3 |
4 | 2 | 01.01.2014 | 30.06.2014 | 6 |
5 | 3 | 01.01.2014 | 30.06.2014 | 9 |
Next table contains IDs (y axis) and Months (x axis)
| F | G | H | I | J | K | L |
---| ----|--------|--------|--------|--------|--------|--------|
1 | ID | 201401 | 201402 | 201403 | 201404 | 201405 | 201406 |
2 | 1 | | | | | | |
3 | 2 | | | | | | |
4 | 3 | | | | | | |
And I wish to feel this second table like this:
| ID | 201401 | 201402 | 201403 | 201404 | 201405 | 201406 |
| ----|--------|--------|--------|--------|--------|--------|
| 1 | 1 | 1 | 1 | 1 | 3 | 3 |
| 2 | 6 | 6 | 6 | 6 | 6 | 6 |
| 3 | 9 | 9 | 9 | 9 | 9 | 9 |
I tried to use Index and Match, but without any good results because I haven't found a posibility to use IF (if (
Could anybody help?
You can get what you're looking for with SUMPRODUCT
Given the layout you provided, this formula should work when put in G2 and filled down and over
=SUMPRODUCT(--($A:$A=$F2),--($B:$B<=G$1),--($C:$C>G$1),$D:$D)
That looks in column A for an ID matching F2, then for every one it finds of those:
It checks the date in column B against the date in G1
It checks the date in column C against the date in G1
If all criteria match, it returns the value in Column D
This assumes you only have one entry for each period, otherwise it will sum them.
Also, you can use SUMIFS, it's a little less easy to read but I think it's slightly more efficient than SUMPRODUCT (I'm not positive, just anecdotal evidence from usage)
=SUMIFS($D:$D,$A:$A,"="&$F3,$B:$B,"<="&G$1,$C:$C,">"&G$1)
It does the exact same thing, just with different syntax.

Resources