Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve and rebalance Task/Subtask/Shift #1112

Open
mokun opened this issue Oct 28, 2023 · 25 comments
Open

Improve and rebalance Task/Subtask/Shift #1112

mokun opened this issue Oct 28, 2023 · 25 comments
Milestone

Comments

@mokun
Copy link
Member

mokun commented Oct 28, 2023

Describe the situation

  • Currently, there are various task imbalance and anomaly that we should address, prior to releasing 3.7.0

Expected and unexpected behavior

  1. Should a person be digging local regolith at night ?
  2. In a 16-person settlement such as Arcadia, should we have 14 settlers taking the night off, while leaving only 2 on the night duty ?
  3. We haven't seen anyone starting a conversation lately. Need to fix Conversation and ConversationMeta class.
  4. How should we properly handle having two settlers conversing with each other ?
  5. How should we track how often (its frequency) a task class is done during OFF-DUTY ?
    • Since this person chooses to perform this class without external pressure, it means that a person is either reinforcing his interest in doing it or shifting his interest away and thus getting tired of it and not wanting to do it.
    • The pattern and frequency should cause a slight modification to a person's preference score on this task.

Java classes involved

  • Conversation, Preference
  • Modify getPreferenceScore() to have a string param (task or meta task's name), rather than having to bother with MetaTask class :
	/**
	 * Obtains the preference score modified by its priority for a meta task.
	 * 
	 * @param metaTask
	 * @return the score
	 */
	public int getPreferenceScore(MetaTask metaTask) {
		int result = 0;

		// DO NOT use MetaTask instance as the key because they are not serialized and
		// hence on a reload will not find a match since the instance will be different.
		String s = getStringName(metaTask);
		if (scoreStringMap.containsKey(s)) {
			result = scoreStringMap.get(s);
		}

		return result;
	}

Screenshots
image

Specifications

  • pre 3.7.0 build 8839
@mokun
Copy link
Member Author

mokun commented Oct 28, 2023

After the commit, that's what it looks like right now as follows

image

image

Note that they are both in the same building when Daria starts a conversation with Rithvik.

mokun added a commit that referenced this issue Oct 28, 2023
10.28.2023

- change: rename Conversation to Converse
- change: rename ConversationMeta to ConverseMeta
- change: add calling a subtask in invitee
- new: add targetID and target person in Task for invitee or initiator
- change: revise addSubTask() to return the status of whether a subtask
          can be added or not

Relates to #1112
@bevans2000
Copy link
Member

Using string is too fragile, the string changes due to language and it stops. There is too much reliance on strings.
The way Tasks are selected feels a bit adhoc with custom rules in place. If we can consolidate how they are score we can start to rebalance to get scores similiar so better selection is done.
We do have a problem with science studies in that too many are being created. We either need to reduce who can start them based on Role/job or have a limit per Settlement.

@bevans2000
Copy link
Member

As to Conversation Task. I have no idea how it is selected. Change the MetaTask so we can see the logic in the scoring and work out why it is low down.

@mokun
Copy link
Member Author

mokun commented Oct 28, 2023

Using string is too fragile, the string changes due to language and it stops. There is too much reliance on strings.

How about using the 'SimpleName' of that MetaTask or that Task ?

If I need to get the preference score of a Task, it's a waste to have to first create the Task class by new ConverseMeta(person) in order to get the score.

@bevans2000
Copy link
Member

How about using the 'SimpleName' of that MetaTask or that Task ?

If I need to get the preference score of a Task, it's a waste to have to first create the Task class by new Converse(person) in order to get the score.

I agree but preference is based on the MetaTask and these instances are already created, so the object is already in memory. If we pass a string every call of this method would have to change. But in the current approach how we choice the preference is hidden from the caller which is good abstracted design.

mokun added a commit that referenced this issue Oct 29, 2023
10.29.2023

- new: create converseMeta in MetaTaskUtil for use in EatDrink
          and Converse
- change: rename TaskProbabilityUtil to TaskUtil
- change: relocate isIdleTask() from Converse to TaskUtil
- fix: revert the previous incorrect change of word back
       to "conversation" in mars-sim-console package
- update: change flatlaf to 3.2.5

Relates to #1112 and
7b61459
@bevans2000
Copy link
Member

In a 16-person settlement such as Arcadia, should we have 14 settlers taking the night off, while leaving only 2 on the night duty ?

Sorry, I missed this is the original post. This has nothing to do with Tasks. It is all configurable from the ShiftSpec which is configured in settlement.xml. Either change one of the existing patterns and create a new one and assign it to a settlement template. Don't add any custom code to handle the edge cases though; this is totally configurable now. I expect that Settlement is using the "Skeleton Night Shift" shift pattern which has only 10% of the population active at night since that is what the pattern is addressing.

@mokun
Copy link
Member Author

mokun commented Oct 30, 2023

I expect that Settlement is using the "Skeleton Night Shift" shift pattern which has only 10% of the population active at night since that is what the pattern is addressing.

So what makes a settlement commander decide to take a skeleton (10%) night shift versus a 20%, 30% or 50% night shift ?

Can we create a TabPanelShift and use a combobox for players to choose various types of shift for a settlement ?

@bevans2000
Copy link
Member

Not really that easy because the Shift are constructed and persons assigned as they join the Settlement. Just change the Shift Pattern assigned in Settlement template

@mokun
Copy link
Member Author

mokun commented Oct 31, 2023

I can now see in SettlementConfig's parseItemXML(), we have the following :

		//Look up the shift pattern
		String shiftPattern = templateElement.getAttributeValue(SHIFT_PATTERN);
		if (shiftPattern == null) {
			if (defaultPopulation >= 12) {
				shiftPattern = DEFAULT_3SHIFT;
			}
			else {
				shiftPattern = DEFAULT_2SHIFT;
			}
		}
		ShiftPattern pattern = getShiftPattern(shiftPattern);

		// Add templateID
		SettlementTemplate template = new SettlementTemplate(
				settlementTemplateName,
				description,
				predefined,
				sponsor,
				pattern,
				defaultPopulation,
				defaultNumOfRobots);

It seems that currently the shift pattern is determined by its initial population. When it's more than 12, then, it uses the "standard 3 shift", other it's "standard 2 shift", right ?

But we have actually defined a total of 4 shift patterns in setlements.xml as follows :

	<!-- The Standard patterns are the default and but always be present. 
		The others can be added/deleted -->
	<shifts>
		<shift-pattern name="Standard 3 Shift" rotation-sols="2">
			<shift name="A" start="200" end="550" pop-percentage ="40"/>
			<shift name="B" start="550" end="900" pop-percentage ="40"/>
			<shift name="Night" start="900" end="200" pop-percentage ="20"/>
		</shift-pattern>
		<shift-pattern name="Standard 2 Shift" leave-perc="3" rotation-sols="4">
			<shift name="Day" start="200" end="700" pop-percentage ="50"/>
			<shift name="Night" start="700" end="200" pop-percentage ="50"/>
		</shift-pattern>
		<shift-pattern name="Skeleton Night Shift" leave-perc="3" rotation-sols="2">
			<shift name="Day" start="500" end="930" pop-percentage ="90"/>
			<shift name="Night" start="900" end="530" pop-percentage ="10"/>
		</shift-pattern>
		<shift-pattern name="Long 3 Shift" rotation-sols="4">
			<shift name="A" start="200" end="600" pop-percentage ="40"/>
			<shift name="B" start="500" end="900" pop-percentage ="40"/>
			<shift name="Night" start="900" end="200" pop-percentage ="20"/>
		</shift-pattern>
	</shifts>

@mokun
Copy link
Member Author

mokun commented Oct 31, 2023

I can see that the attribute "shift-pattern" is optional in settlemnet.xsd as follows :

   <xs:element name="template">
        <xs:complexType>
            <xs:sequence>
                <xs:element ref="building"  maxOccurs="unbounded"/>
                <xs:element ref="vehicle"  minOccurs="0" maxOccurs="unbounded"/>
                <xs:element ref="robot"  minOccurs="0" maxOccurs="unbounded"/>
                <xs:element ref="equipment"  minOccurs="0" maxOccurs="unbounded"/>
				<xs:element ref="bin"  minOccurs="0" maxOccurs="unbounded"/>
                <xs:element ref="resource"  minOccurs="0" maxOccurs="unbounded"/>
                <xs:element ref="part"  minOccurs="0" maxOccurs="unbounded"/>
                <xs:element ref="part-package" minOccurs="0" maxOccurs="unbounded"/>
                <xs:element ref="building-package" minOccurs="0" maxOccurs="unbounded"/>               
                <xs:element ref="resupply" minOccurs="0" maxOccurs="1"/>
            </xs:sequence>
            <xs:attribute name="name" type="xs:string"/>
            <xs:attribute name="description" type="xs:string"/>
            <xs:attribute name="sponsor" type="xs:string"/>
            <xs:attribute name="shift-pattern" type="xs:string"  use="optional"/>
            <xs:attribute name="default-population" type="xs:integer"/>
            <xs:attribute name="number-of-robots" type="xs:integer"/>
        </xs:complexType>
    </xs:element>

And I can see the /sh console command for querying the shift info of a settlement as follows :

01-Adir-01:567 Heritage >  ​/sh
                          Name : Standard 3 Shift
                Shift Rotation : 2 sols
       Maximum Worker Rotation : 10%
                        Offset : 950 mSol
      Name | Allocated | Start | End
------------------------------------
         A |        15 |   150 | 500
         B |        14 |   500 | 850
     Night |         7 |   850 | 150

It would be great to let player create new shift patterns or at least choose a different shift pattern than the one predefined for a settlement in xml.

@mokun
Copy link
Member Author

mokun commented Oct 31, 2023

One question is, say if a settlement initially has 24 populations but 12 of them die, will it intelligently switch to another shift pattern to cope with the loss of settlers ?

For the time being, I'll go to add "Standard 4 Shift" for that brand new "Hub Settlement" that has 36 people just to see how realistic it is to have 4 shifts.

mokun added a commit that referenced this issue Oct 31, 2023
10.30.2023

- new: add new shift pattern definition of "Standard 4 shift" in
       settlements.xml
- new: add STANDARD_4_SHIFT in SettlementConfig
- change: revise parseItemXML() in SettlementConfig to make use of 3
          shift patterns.

Relates to #1112
@bevans2000
Copy link
Member

Ok.

@bevans2000
Copy link
Member

Remember the ShiftManager automatically rotates Persons around the Shifts so this rebalances when persons die. The Person is given a day's, leave when changing pattern to allow their sleep to adjust.

@mokun
Copy link
Member Author

mokun commented Oct 31, 2023

Remember the ShiftManager automatically rotates Persons around the Shifts so this rebalances when persons die

It's good it does that to rebalance the missing shift. However, the shift pattern should also be under reconsideration for a change when

  • a high percentage of people are on missions, thus leaving their posts in the settlement.
  • a high turnover of personnel due to
    • death
    • sickness (need bed rest)
    • migration (to other settlements or back to Earth or Moon)

The Person is given a day's, leave when changing pattern to allow their sleep to adjust.

Hmm... giving a settler one day of leave is very generous indeed :D

For a small settlement, we may not have that kind of luxury though.

mokun added a commit that referenced this issue Nov 1, 2023
11.01.2023

- fix: add restoring targetID in Task's reinit() as used in Converse
       task

Relates to #1112
mokun added a commit that referenced this issue Nov 1, 2023
11.01.2023

- fix: add restoring targetID in Task's reinit() as used in Converse
       task
- fix: allow colonists set to be non-transient in Population

Relates to #1112
mokun added a commit that referenced this issue Nov 1, 2023
11.01.2023

- fix: call setTarget() in Converse
- fix: correct null building in lookTobeAssignedABed() in Sleep
- change: make Colonist serializable

Relates to #1112
mokun added a commit that referenced this issue Nov 1, 2023
11.01.2023

- change: make target and targetID private in Task
- change: use getTarget() and getTargetID() in Converse

Relates to #1112
@mokun mokun changed the title Improve and rebalance Task/Subtask Improve and rebalance Task/Subtask/Shift Nov 2, 2023
@mokun
Copy link
Member Author

mokun commented Nov 2, 2023

Here in Catarina, a 4-person settlement, I found this somewhat unreasonable :

image

3 of them are having Night Off Duty shift. 1 of them are on Night On Leave.

So no one is on duty at all.

Can we set some constraints on allowing people to be off duty based on both the percentage and # of available personnel ?

@bevans2000
Copy link
Member

bevans2000 commented Nov 2, 2023

Here in Catarina, a 4-person settlement, I found this somewhat unreasonable :

3 of them are having Night Off Duty shift. 1 of them are on Night On Leave.

So no one is on duty at all.

Can we set some constraints on allowing people to be off duty based on both the percentage and # of available personnel ?

What was the Shift Pattern assigned to the Settlement? The 1 person On Leave is probably changing shift to Day.
There are UnitTest to cover the ShiftPattern logic so the logic is correct. It's more to do with the context.
I will look into it when I get time which might be this weekend if lucky.

@mokun
Copy link
Member Author

mokun commented Nov 2, 2023

What was the Shift Pattern assigned to the Settlement?

For now, it's STANDARD_2_SHIFT for any settlements with less than 12 people.

@mokun
Copy link
Member Author

mokun commented Nov 5, 2023

Somehow, Kyocera is somehow on STANDARD_2_SHIFT (the Day/Night 2 shift pattern), even though it has 16 settlers :

image

But somehow in Arcadia, it's on Skeleton Night Shift.

image

May be I'll change both to STANDARD_3_SHIFT since they have 16 people, right ?

@mokun
Copy link
Member Author

mokun commented Nov 30, 2023

image

So for this 16-people settlement, 14 are on Day duty. Only 2 are on Night duty.

Is it reasonable ?

@mokun
Copy link
Member Author

mokun commented Nov 30, 2023

And you said when settlers come home from a mission, they will have the rest of the day off, right ?

image

@mokun
Copy link
Member Author

mokun commented Nov 30, 2023

And you said when settlers come home from a mission, they will have the rest of the day off

Anywhere would tell me if a person would have the day off on sol ___ until what time ?

@bevans2000
Copy link
Member

image

So for this 16-people settlement, 14 are on Day duty. Only 2 are on Night duty.

Is it reasonable ?

Look at which Shift Schedule has been assigned. That defines how many are on each Shift. It us all configuration driven and that shouldn't be changed. So if you think it's wrong change the automatic selection of the Shift schedule, don't add hard coded logic.

@bevans2000
Copy link
Member

And you said when settlers come home from a mission, they will have the rest of the day off

Anywhere would tell me if a person would have the day off on sol ___ until what time ?

I think they get the rest of the Shift off as leave.

@mokun
Copy link
Member Author

mokun commented Nov 30, 2023

I think they get the rest of the Shift off as leave.

but how would a player get notified that a person gets the rest of the shift or the rest of the day off ?

The code may have done it. But is there a method you can call to find out and can you add a label in the Person Window saying he will be on leave till sol x: xxx ?

@bevans2000
Copy link
Member

Sure, we show the extended Shift description somewhere. That can be changed.
But I honestly can't remember if the leave duration is recorded in the ShiftSlot.

@mokun mokun added this to the 3.8.0 milestone Dec 1, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants