Autoscheduler with lag not working correctly


#1

I’m trying to sort out a bug in our gantt implementation, where the users is able to drag successor tasks which in turn changes the lag value. Unfortunately it appears than when this happens, it breaks the autoscheduler and we start seeing unusual behaviour. See this snippet http://snippet.dhtmlx.com/5/e30185adb

In the example above, when the page loads you are able to move “Task #1” and it will move “Task #2” as expected. If you then move “Task #2” forward 1 day it moves correctly, however moving “Task #1” now has a few issues. If you try moving “Task #1” to start on the 1st April, “Task #2” remains in place and does not move with it.

If you then attempt to move “Task #2” back to the 2nd April, it won’t move even though it is correctly updating the lag of the link. If you try and do that again, it still doesn’t move but the lag value gets decreased again, and now moving “Task #1” has no impact on “Task #2” at all.

I’m not entirely sure what’s going on here, or whether I’m using the wrong event listeners, but I cannot get this working


#2

Hello,
It works that way because of the constraint logic. After you move a task, it obtains the SNET constraint. When you move its predecessor to an earlier date, the task cannot move to the earlier date because of the SNET constraint:
https://docs.dhtmlx.com/gantt/desktop__auto_scheduling.html#versioncompatibility
Also, you connected the auto-scheduling extension from an old Gantt version(6.3). Since the 7.0 version, you need to use the plugins method:
https://docs.dhtmlx.com/gantt/api__gantt_plugins.html
Here is the updated snippet that visualizes the constraints after you drag a task:
http://snippet.dhtmlx.com/5/057c6f905

The issue that you cannot move Task #2 to the 2nd of April occurs because of your custom implementation.
You can modify the constraint date in the onBeforeTaskChanged event handler:
http://snippet.dhtmlx.com/5/c74a6f209

Maybe, you don’t need to use the constraint logic. You can use the old logic that was used before the 6.1 version and enable the strict mode.
In that case, the tasks will always be auto-scheduled to keep the earliest date:
http://snippet.dhtmlx.com/5/cdccf79eb

If the approaches above don’t help you, please, clarify what exactly you need and why you need to do that.


#3

Thanks for getting back to me so quickly. I realise I wasn’t using the right way of enabling the autoscheduling plugin, but when I originally tried it wasn’t working so I wasn’t sure if the pro version was available in the snippets until I just found another one that worked so I used that.

Thank you for the snippets, they do provide some additional clarity, however they’re still all showing some of the same issues I’m facing regardless of the constraints. For example both of these ones:

http://snippet.dhtmlx.com/5/c74a6f209?_ga=2.203224019.353464876.1634113742-1893993044.1632819757
http://snippet.dhtmlx.com/5/057c6f905?_ga=2.135788147.353464876.1634113742-1893993044.1632819757

In both of these, when it first loads if I immediately move “Task #2” 1 day forwards to “03 April”, it moves fine. If I now try and move the same task back to “02 April” it doesn’t move and jumps back. However, if you double click the task to trigger the auto scheduler, it DOES jump back correctly.

So, it seems as though my lag that I calculate in “onBeforeTaskChanged” is correct, and the auto scheduler does take it into account, but it seems as though the auto scheduler isn’t taking it into account when it runs immediately after moving the task.

Given that the auto scheduler is working correctly when I double click, I’d expect the exact same result when it ran straight after I moved a task.

in our app I’ve added a small workaround which works but it’s not very nice, and that is to manually call the auto scheduler in onAfterTaskDrag but this feels like a bit of a hack


#4

Hello,

This snippet doesn’t change anything with your solution, it only visualizes the constraints:
https://snippet.dhtmlx.com/5/057c6f905
So, it is expected that it works almost the same way as in your snippet.

This snippet works better, but you need to auto-schedule a task after updating the link:
https://snippet.dhtmlx.com/5/c74a6f209

I checked how the code works in that part, and it seems that you modify the logic Gantt uses to auto-schedule tasks. To be more specific, you do the same thing with the lag as Gantt, so some internal functions work in a different way.

For Gantt, the lag parameter of the link should remain the same when you drag tasks, then the tasks will keep the distance after they are auto-scheduled. If you do that before or after dragging the tasks, it should work correctly.

One of the possible solutions for you would be to return false in that event handler to not apply the changes, then manually update the task via the API methods:
http://snippet.dhtmlx.com/5/e008c0934

Please, clarify why you want to change the lag value after dragging tasks.


#5

As you suggest in that second snippet, I have to explicitly invoke the auto scheduler which doesn’t feel right.

The reason I’m trying to change the lag value is because we want to allow users to drag tasks around freely and have the lag value automatically updated, without having to specify the lag value in a UI. Every example I’ve found on the dhtmlx website lets me move a task forwards, but never backwards (assuming due to the constraints). For example this demo https://docs.dhtmlx.com/gantt/samples/02_extensions/12_auto_scheduling.html

Here for example, I am able to move Task #2.3 forwards and it will leave a gap after Task #2.2, but if I try and move it backwards so it starts before Task #2.2 ends, I can’t. What I want to happen, is when I move it before the end of Task #2.2 it changes the lag to a negative value.

The other thing I’ve noticed in those examples, is that the lag value is never set on the link which is why I’m trying to set it after moving things around. If it’s not set, the moment the auto scheduler runs everything jumps back to a different position which we don’t want.


#6

Hello,

The reason I’m trying to change the lag value is because we want to allow users to drag tasks around freely and have the lag value automatically updated, without having to specify the lag value in a UI. Every example I’ve found on the dhtmlx website lets me move a task forwards, but never backwards (assuming due to the constraints). For example this demo https://docs.dhtmlx.com/gantt/samples/02_extensions/12_auto_scheduling.html

Thank you for the clarification. If you want to allow users to drag tasks to any position, do you really need to use the auto-scheduling feature? Without that, Gantt won’t move tasks at all:
In most of the samples, Gantt doesn’t use auto-scheduling and allows placing tasks to any date. For example:
https://docs.dhtmlx.com/gantt/samples/01_initialization/16_projects_and_milestones.html


Here for example, I am able to move Task #2.3 forwards and it will leave a gap after Task #2.2, but if I try and move it backwards so it starts before Task #2.2 ends, I can’t. What I want to happen, is when I move it before the end of Task #2.2 it changes the lag to a negative value.

It is expected behavior that you cannot move the task to an earlier date as according to auto-scheduling logic, successor tasks with the FS link cannot start before their predecessors end:
https://docs.dhtmlx.com/gantt/desktop__auto_scheduling.html#timeconstraintsfortasks
You can use the MSO or MFO constraints that allow moving tasks to any position.


https://docs.dhtmlx.com/gantt/desktop__auto_scheduling.html#timeconstraintsfortasks


The other thing I’ve noticed in those examples, is that the lag value is never set on the link which is why I’m trying to set it after moving things around. If it’s not set, the moment the auto scheduler runs everything jumps back to a different position which we don’t want.

The lag parameter specifies the distance between tasks. But Gantt uses the constraint logic. If you move a predecessor task to a new date, the successor task will start at the same time its successor ends. When the lag parameter is specified, Gantt will keep the distance between tasks. For example:


http://snippet.dhtmlx.com/5/6c3aec7b2

If you only want to drag a predecessor task and move all its successor tasks, it is not necessary to use auto-scheduling. Here is an example of the implementation that allows you to do that:
https://docs.dhtmlx.com/gantt/desktop__dragging_dependent_tasks.html#movingtasksmanually
Here is the snippet:
http://snippet.dhtmlx.com/5/d77ce2b39


#7

Thank you for the clarification. If you want to allow users to drag tasks to any position, do you really need to use the auto-scheduling feature? Without that, Gantt won’t move tasks at all:
In most of the samples, Gantt doesn’t use auto-scheduling and allows placing tasks to any date. For example:
https://docs.dhtmlx.com/gantt/samples/01_initialization/16_projects_and_milestones.html

That might simplify things, though without the auto scheduler wouldn’t I lose the automatic calculation of non-workdays? e.g if I move a task to a weekend, it needs to move so it isn’t on the weekend, or so it spans the weekend but maintains the correct duration. Would I have to implement all of this myself?

If you only want to drag a predecessor task and move all its successor tasks, it is not necessary to use auto-scheduling. Here is an example of the implementation that allows you to do that:
https://docs.dhtmlx.com/gantt/desktop__dragging_dependent_tasks.html#movingtasksmanually 2
Here is the snippet:
http://snippet.dhtmlx.com/5/d77ce2b39

As mentioned previously, would I need to calculate the jumping of non-workdays?

I understand the concepts behind the auto scheduler and constraints, but it still feels like there is a bug somewhere based on everything you’ve described. Specifically looking at this snippet you kindly provided me before https://snippet.dhtmlx.com/5/c74a6f209?_ga=2.218372057.135532133.1634660101-1893993044.1632819757

When it loads everything is normal. Now I move Task #2 forward and we can see the constraint applying as you suggest. It’s now “Start no earlier than”. The link has been modified to have a lag of 1.

Now I move Task #2 back to the original position

Now you can see that the constraint type has not change, but the constraint date HAS changed correctly to the 2nd April, yet the task itself was moved back to the 3rd of April. If I double click the task to trigger the auto scheduler, it then moves the task back to the correct position.

I’m not understanding how this is expected behaviour. The constraint is modified, the lag is modified, and when the auto scheduler is run after all the changes are made it does work correctly, but it fails to work correctly immediately after making a change.


I’m happy to look at not using the auto scheduler and doing it manually, but we do need the ability to not allow scheduling of tasks on non-workdays


#8

Hello,

That might simplify things, though without the auto scheduler wouldn’t I lose the automatic calculation of non-workdays? e.g if I move a task to a weekend, it needs to move so it isn’t on the weekend, or so it spans the weekend but maintains the correct duration. Would I have to implement all of this myself?

That is the work time feature:
https://docs.dhtmlx.com/gantt/desktop__working_time.html
It can work without auto-scheduling.
Here is an example:
http://snippet.dhtmlx.com/ed18c1a7e

To make a task move to the closest work time, you need to enable the corect_work_time config:
https://docs.dhtmlx.com/gantt/api__gantt_correct_work_time_config.html

Here is an example:
http://snippet.dhtmlx.com/5/29c9e3c8a


I’m not understanding how this is expected behaviour. The constraint is modified, the lag is modified, and when the auto scheduler is run after all the changes are made it does work correctly, but it fails to work correctly immediately after making a change.

As I described in the previous message, it works that way because you modify the lag parameter after you started dragging the task, but before the changes are applied. Gantt uses the lag parameter in internal calculations. So, when you manually change it in the middle of the process, you redefine the logic Gantt uses. I suppose you try to apply the lag parameter from MS Project or other programs, but it doesn’t work the same way in Gantt.


#9

Alright thanks I’ll take a look through these

As I described in the previous message, it works that way because you modify the lag parameter after you started dragging the task, but before the changes are applied. Gantt uses the lag parameter in internal calculations. So, when you manually change it in the middle of the process, you redefine the logic Gantt uses. I suppose you try to apply the lag parameter from MS Project or other programs, but it doesn’t work the same way in Gantt.

This doesn’t seem quite right in my mind but fair enough. I’ve got a work around in place at the moment which is working so I’ll stick with this for now and see if we can remove the auto scheduler entirely at some point.

Thanks for you help