How To solve “Bailing out of neverEnding selector to avoid infinite loop” error when I've used @PlanningPin In Optaplanner?

huangapple go评论67阅读模式
英文:

How To solve “Bailing out of neverEnding selector to avoid infinite loop” error when I've used @PlanningPin In Optaplanner?

问题

我想使用optaplanner的“pin”功能来处理不可移动的操作。然而,我遇到了“Bailing out of neverEnding selector (Filtering(FromSolutionEntitySelector(PersonAssignment))) to avoid infinite loop.”错误。我尝试过使用@PlanningPin和movableEntitySelectionFilter两种方式。Optaplanner版本为7.32.0 final,我还尝试了版本7.44.0.Final。我搜索了很多资料,发现您在版本7.31.0.Final中已经解决了这个问题。

我已经生成了我的领域模型,它运行良好。我的问题是有多个酒店,人们在不同的时间入住酒店。每个酒店的容量不同,我想要将人们分配给酒店,如果有足够的空间的话。我还有许多关于分配的规则。我的领域模型包括两个@PlanningEntity,customShadowVariable和TimeGrain。结构如下:

@PlanningEntity(movableEntitySelectionFilter = PersonAssignmentSelectionFilter.class)
public class PersonAssignment extends AbstractPersistable {

private Person person;

private TimeGrain startingTimeGrain;

private TimeGrain endTime; // This added

private HotelDomain hotelDomain;

public TimeGrain getStartingTimeGrain() {
  return startingTimeGrain;
}

public void setStartingTimeGrain(TimeGrain startingTimeGrain) {
  this.startingTimeGrain = startingTimeGrain;
}

public TimeGrain getEndTime() {
  return endTime;
}

public void setEndTime(TimeGrain endTime) {
  this.endTime = endTime;
}

@PlanningVariable(valueRangeProviderRefs = { "hotelDomainRange" }, nullable = true)
public HotelDomain getHotelDomain() {
  return hotelDomain;
}

public void setHotelDomain(HotelDomain hotelDomain) {
  this.hotelDomain = hotelDomain;
}
...
}
@DeepPlanningClone 
public class HotelDomain extends AbstractPersistable {

private String hotelName;

@CustomShadowVariable(variableListenerRef = @PlanningVariableReference(variableName = "tightOccupancy, personAssignment))
   private Map<Integer, HotelOccupancyPerSlot> hotelOccupancyMap;
...
}
@PlanningEntity
public class HotelOccupancyPerSlot extends AbstractPersistable {

 @CustomShadowVariable(variableListenerClass = HotelDomainVariableListener.class, sources = {
         @PlanningVariableReference(entityClass = PersonAssignment.class, variableName = "hotelDomain") })
   private Integer tightOccupancy; // days

   @CustomShadowVariable(variableListenerRef = @PlanningVariableReference(variableName = "tightOccupancy"))
   private List<PersonAssignment> personAssignments;
...
}
public class HotelDomainVariableListener implements VariableListener<PersonAssignment> {
...
}

配置文件config.xml如下:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE xml>
<solver>
	<moveThreadCount>3</moveThreadCount> <!-- To solve faster by saturating multiple CPU cores -->
	<solutionClass>com.domain.HotelAccomodation</solutionClass>
	<entityClass>com.domain.PersonAssignment</entityClass>
	<entityClass>com.domain.HotelOccupancyPerSlot</entityClass>

	<scoreDirectorFactory>
		<scoreDrl>solver/solverScoreRules.drl</scoreDrl>
	</scoreDirectorFactory>
  
	<termination>
		 <minutesSpentLimit>15</minutesSpentLimit>
	</termination>
</solver>

如果我在HotelOccupancyPerSlot中使用@PlannigPin就没有问题,但我只想在PersonAssignment类中使用它(或过滤器),因为它是我的基本类。是否有任何建议?我需要在配置中添加一些内容吗?

谢谢您 How To solve “Bailing out of neverEnding selector to avoid infinite loop” error when I've used @PlanningPin In Optaplanner?

英文:

I want to use "pin" feature of optaplanner for immovable operations. However i get "Bailing out of neverEnding selector (Filtering(FromSolutionEntitySelector(PersonAssignment))) to avoid infinite loop." error. I've tried both with @PlanningPin and movableEntitySelectionFilter. Optaplanner version is 7.32.0 final, also i tried with version 7.44.0.Final. I've searched a lot and as can i see you've solved this problem in version 7.31.0.Final.

I've generated my domain and it is working well. Idea of my problem is there are more then one hotel. People come to hotel at different hours. Each hotel has different capacity and i want to asign people to a hotel if there is enough space. I've also many rules about assignment. My domain model consists of two @PlanningEntity,customShadowVariable and also TimeGrain. Structure is below:

@PlanningEntity(movableEntitySelectionFilter = PersonAssignmentSelectionFilter.class)
public class PersonAssignment extends AbstractPersistable {

private Person person;

private TimeGrain startingTimeGrain;

private TimeGrain endTime; // This added

private HotelDomain hotelDomain;


public TimeGrain getStartingTimeGrain() {
      return startingTimeGrain;
}

public void setStartingTimeGrain(TimeGrain startingTimeGrain) {
      this.startingTimeGrain = startingTimeGrain;
}

public TimeGrain getEndTime() {
      return endTime;
}

public void setEndTime(TimeGrain endTime) {
      this.endTime = endTime;
}

@PlanningVariable(valueRangeProviderRefs = { &quot;hotelDomainRange&quot; }, nullable = true)
	public HotelDomain getHotelDomain() {
      return hotelDomain;
}

public void setHotelDomain(HotelDomain hotelDomain) {
      this.hotelDomain = hotelDomain;
}
......
}

@DeepPlanningClone 
public class HotelDomain extends AbstractPersistable {

private String hotelName;

@CustomShadowVariable(variableListenerRef = @PlanningVariableReference(variableName = &quot;tightOccupancy, personAssignment))
   private Map&lt;Integer, HotelOccupancyPerSlot&gt; hotelOccupancyMap;

......
}

@PlanningEntity
public class HotelOccupancyPerSlot extends AbstractPersistable {

 @CustomShadowVariable(variableListenerClass = HotelDomainVariableListener.class, sources = {
         @PlanningVariableReference(entityClass = PersonAssignment.class, variableName = &quot;hotelDomain&quot;) })
   private Integer tightOccupancy; // days

   @CustomShadowVariable(variableListenerRef = @PlanningVariableReference(variableName = &quot;tightOccupancy&quot;))
   private List&lt;PersonAssignment&gt; personAssignments;

.......
}

public class HotelDomainVariableListener implements VariableListener&lt;PersonAssignment&gt; {
......
}

config.xml is:

&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;
&lt;!DOCTYPE xml&gt;
&lt;solver&gt;
	&lt;moveThreadCount&gt;3&lt;/moveThreadCount&gt; &lt;!-- To solve faster by saturating multiple CPU cores --&gt;
	&lt;solutionClass&gt;com.domain.HotelAccomodation&lt;/solutionClass&gt;
	&lt;entityClass&gt;com.domain.PersonAssignment&lt;/entityClass&gt;
	&lt;entityClass&gt;com.domain.HotelOccupancyPerSlot&lt;/entityClass&gt;

	&lt;scoreDirectorFactory&gt;
		&lt;scoreDrl&gt;solver/solverScoreRules.drl&lt;/scoreDrl&gt;
	&lt;/scoreDirectorFactory&gt;
  
	&lt;termination&gt;
		 &lt;minutesSpentLimit&gt;15&lt;/minutesSpentLimit&gt;
	&lt;/termination&gt;
&lt;/solver&gt;

If i use @PlannigPin in HotelOccupancyPerSlot there is no problem but i want to use it(or filter) only in PersonAssignment class because it is my basic class. Is there any suggestion? Should i add something to config?

Thank You How To solve “Bailing out of neverEnding selector to avoid infinite loop” error when I've used @PlanningPin In Optaplanner?

答案1

得分: 1

"Bailing out" 警告发生在移动选择过滤器过滤掉每个移动时(它从不返回true)。这不是错误,而是警告,因为如果你只看到它一次,从理论上讲在某些情况下可能是一个无害的巧合。

无论如何,什么情况下过滤器会对所有已选移动返回false?在以下情况下会出现这种情况:

  • A) 你在solverConfig.xml中配置了一个从不返回true的自定义移动过滤器
  • B) 解决方案值范围没有值 - OptaPlanner在7.44+中进行了检查,并自动执行了正确的操作。但如果有2个计划变量,而只有1个变量没有值,则不确定是否会执行正确的操作...
  • C) 解决方案值范围只有一个值 - 这意味着移动是不可执行的(isDoable()返回false)。尽管我不记得这会是个问题。
  • D) 解决方案值范围没有非固定值。参见B)
  • E) 解决方案值范围只有一个非固定值。参见C)

检查一下你的输入数据。你是否碰巧遇到了B、C、D或E这些情况?

英文:

The "Bailing out" warning happens when a move selection filter is filtering out every move (it never returns true). It's not an error, but a warning, because there if you see it only once, it could be a harmless fluke in theory in some cases.

Anyway, when does a filter return false for all selected moves? In these cases:

  • A) you configured a custom move filter in solverConfig.xml that never returns true
  • B) the solution value range has no values - OptaPlanner checks for that ins 7.44+ and does the right thing automatically. Not sure if it does the right thing if there are 2 planning variables and only 1 has no values...
  • C) the solution value range has a single value - that would mean the move isDoable() false. I don't recall this being a problem though.
  • D) the solution value range has no non-pinned value. See B)
  • E) the solution value range has only 1 non-pinned value. See C)

Take a look at your input data. Are you dealing with case B, C, D or E by any chance?

huangapple
  • 本文由 发表于 2020年10月13日 22:18:19
  • 转载请务必保留本文链接:https://go.coder-hub.com/64337004.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定