optaplanner rule does not properly solve

143 views Asked by At

I made an optaplanner rule (see below).

//in expressway long tunnel(over 1km), equipment interval(400m)

rule "lcs_transport_tunnel_expway"

when
  $road : RoadVO(roadCtgry=="EXPWAY")
  $t1 : Transport(transportCode=="TUNNEL", $direction:direction,
                    Math.abs(mileageBegin-mileageEnd)>1000, 
                    $mileageBegin:mileageBegin, $mileageEnd:mileageEnd )
  $e0 : ItsEquipment(itsClass=="LCS", direction==$direction,
                    mileage >$mileageBegin && <$mileageEnd, $id:id, $mileage:mileage)
  $e1 : ItsEquipment(itsClass== "LCS", direction==$direction, id==$id+1,
                      mileage==$mileage+400 )
then
  scoreHolder.addSoftConstraintMatch(kcontext, 1000);
end

While optaplanner is solving, $e1 is not properly chosen. What is the problem?

Please let me know. Thanks.

1

There are 1 answers

2
Geoffrey De Smet On

(without knowing what the desired result is, it's hard to answer this, but here goes... :)

The 2 selected ItsEquipment's don't constraint that they belong to the original selected Transport (or even the same Transport). They only need to belong to the same direction. Is that your intent?

The $e1 selection has id==$id+1 and mileage==$mileage+400. If your id's are unique, any other condition besides id==$id+1 is pointless (including mileage==$mileage+400).