Skip to content

Commit 8e4259d

Browse files
author
Peter Vaiko
committed
feat: added penalty factor setting for JPS
1 parent ebd4190 commit 8e4259d

5 files changed

Lines changed: 8 additions & 5 deletions

File tree

config/VehicleSettingsSetup.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
<Setting classType="AIParameterBooleanSetting" name="turnOnField" defaultBool="true" isVisible="areCourseSettingsVisible"/>
3434
<!--Avoid Fruit-->
3535
<Setting classType="AIParameterBooleanSetting" name="avoidFruit" defaultBool="true" isExpertModeOnly="true"/>
36+
<Setting classType="AIParameterSettingList" name="penaltyFactor" min="1" max="10" incremental="0.1" default="1" />
3637
<!--Pathfinder Reverse-->
3738
<Setting classType="AIParameterBooleanSetting" name="allowReversePathfinding" defaultBool="true" isExpertModeOnly="true" isVisible="areCourseSettingsVisible"/>
3839
<Setting classType="AIParameterBooleanSetting" name="allowPathfinderTurns" defaultBool="false" isExpertModeOnly="true" isVisible="areCourseSettingsVisible"/>

modDesc.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,7 @@ Changelog 8.0.0.0:
164164
<sourceFile filename="scripts/pathfinder/HybridAStar.lua"/>
165165
<sourceFile filename="scripts/pathfinder/AStar.lua"/>
166166
<sourceFile filename="scripts/pathfinder/HybridAStarWithAStarInTheMiddle.lua"/>
167+
<sourceFile filename="scripts/pathfinder/JumpPointSearch.lua"/>
167168
<sourceFile filename="scripts/pathfinder/PathfinderCollisionDetector.lua"/>
168169
<sourceFile filename="scripts/pathfinder/PathfinderConstraints.lua"/>
169170
<sourceFile filename="scripts/pathfinder/PathfinderContext.lua"/>

scripts/pathfinder/JumpPointSearch.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ function JumpPointSearch:getNextPrimitives(node, primitive)
135135
for _, n in ipairs(primitive.nextPrimitives) do
136136
if n.check then
137137
-- check if the neighbor is valid
138-
local neighborToCheck = State3D(node.x, node.y, n.check:heading()) + n.check
138+
local neighborToCheck = State3D(node.x + n.check.x, node.y + n.check.y, n.check:heading())
139139
if not self:isValidNode(neighborToCheck) or self:isPenaltyChanging(neighborToCheck, node) then
140140
-- we have a forced neighbor
141141
table.insert(nextPrimitives, n.nextPrimitive)

scripts/pathfinder/PathfinderConstraints.lua

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,12 +73,13 @@ function PathfinderConstraints:init(context)
7373
self.initialMaxFruitPercent = self.maxFruitPercent
7474
self.initialOffFieldPenalty = self.offFieldPenalty
7575
self.strictMode = false
76+
self.penaltyFactor = self.vehicle:getCpSettings().penaltyFactor:getValue()
7677
self:resetCounts()
7778
local areaToAvoidText = self.areaToAvoid and
7879
string.format('are to avoid %.1f x %.1f m', self.areaToAvoid.length, self.areaToAvoid.width) or 'none'
79-
self.logger:debug(self.vehicle, 'off field penalty %.1f, max fruit percent: %.1f, field number %d, %s, ignore fruit %s, ignore off-field penalty %s',
80+
self.logger:debug(self.vehicle, 'off field penalty %.1f, max fruit percent: %.1f, field number %d, %s, ignore fruit %s, ignore off-field penalty %s, penalty factor %.1f',
8081
self.offFieldPenalty, self.maxFruitPercent, self.fieldNum, areaToAvoidText,
81-
self.areaToIgnoreFruit or 'none', self.areaToIgnoreOffFieldPenalty or 'none')
82+
self.areaToIgnoreFruit or 'none', self.areaToIgnoreOffFieldPenalty or 'none', self.penaltyFactor)
8283
end
8384

8485
function PathfinderConstraints:resetCounts()
@@ -131,7 +132,7 @@ function PathfinderConstraints:getNodePenalty(node)
131132
end
132133
penalty = penalty + self:calculatePreferredPathPenalty(node)
133134
self.totalNodeCount = self.totalNodeCount + 1
134-
return penalty
135+
return penalty * self.penaltyFactor
135136
end
136137

137138
--- Calculate penalty for this node based on the preferred path. The penalty will be negative to

scripts/pathfinder/PathfinderUtil.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -428,7 +428,7 @@ end
428428
---@param maxIterations number maximum number of iterations
429429
function PathfinderUtil.startPathfinding(vehicle, start, goal, constraints, allowReverse, mustBeAccurate, maxIterations)
430430
PathfinderUtil.overlapBoxes = {}
431-
local pathfinder = HybridAStarWithAStarInTheMiddle(vehicle, 100, maxIterations, mustBeAccurate)
431+
local pathfinder = HybridAStarWithJpsInTheMiddle(vehicle, 100, maxIterations, mustBeAccurate)
432432
return pathfinder, pathfinder:start(start, goal, constraints.turnRadius, allowReverse,
433433
constraints, constraints.trailerHitchLength)
434434
end

0 commit comments

Comments
 (0)