预约系统的optaplanner约束设计

预约系统的optaplanner约束设计,optaplanner,Optaplanner,我想使用optaplanner设计一个预订系统,以下是我的商业模式: Customers (id, name) //Customer table Services(id, name, description, duration) //services that a customer can book, duration can be 15min, 30min, ..., N x 15min Employees(id, name) //Employee tables Appointment(i

我想使用optaplanner设计一个预订系统,以下是我的商业模式:

Customers (id, name) //Customer table
Services(id, name, description, duration)  //services that a customer can book, duration can be 15min, 30min, ..., N x 15min
Employees(id, name)  //Employee tables
Appointment(id, customerId, employeeId, serviceId, startTime, endTime) 
要预约,客户将选择:

  • 任命日期(强制性)
  • 服务清单(强制性)
  • 员工列表(可选)
我想知道我可以设计模型来返回给定日期的可用性列表,给定服务列表。 下面是一个基本的伪代码模型:

@Entity
public class Service extends PanacheEntityBase {

    @Id
    @GeneratedValue
    @NotNull
    private Long id;

    @NotBlank
    private String name;
    private int durationInGrains;
}

public class TimeGrain  {

    public static final int GRAIN_LENGTH_IN_MINUTES = 15;

    private int grainIndex; // unique
    private int startingMinuteOfDay;
}


@Entity
public class Employee extends PanacheEntityBase {

    @PlanningId
    @Id
    @GeneratedValue
    @NotNull
    private Long id;

    @NotBlank
    private String name;
}

@Entity
public class Appointment extends PanacheEntityBase {

    @Id
    @GeneratedValue
    @NotNull
    private Long id;

    private Employee employee;
    private Service service;

    private LocalDateTime startTime;
    private LocalDateTime endTime;
}

@PlanningEntity
public class Availability {

    @PlanningVariable(valueRangeProviderRefs = { "timeGrainRange" })
    private TimeGrain startingTimeGrain;
    
    @PlanningVariable(valueRangeProviderRefs = "providerRange")
    private Provider provider;
    
    private Service service;
}

@PlanningSolution
public class AppointmentAvailability {

    @ValueRangeProvider(id = "timeGrainRange")
    @ProblemFactCollectionProperty
    private List<TimeGrain> timeGrainList;

    @ProblemFactCollectionProperty
    @ValueRangeProvider(id = "providerRange")
    private List<Provider> providerList;

    @ProblemFactCollectionProperty
    @ValueRangeProvider(id = "appointmentsRange")
    private List<Appointment> appointmentList;
    
    @PlanningEntityCollectionProperty
    private List<Availability> availabilityList;

    @PlanningScore
    private HardMediumSoftScore score;
}
@实体
公共类服务扩展了PanacheEntityBase{
@身份证
@生成值
@NotNull
私人长id;
@不空白
私有字符串名称;
私家车的续航时间;
}
公共类时间粒度{
公共静态最终整数粒度长度,单位为分钟=15;
private int grainIndex;//唯一
私人int每天的启动分钟数;
}
@实体
公共类Employee扩展了PanachEntityBase{
@PlanningId
@身份证
@生成值
@NotNull
私人长id;
@不空白
私有字符串名称;
}
@实体
公共类任命扩展了PanacheEntityBase{
@身份证
@生成值
@NotNull
私人长id;
私人雇员;
私人服务;
私有LocalDateTime开始时间;
私有LocalDateTime结束时间;
}
@规划实体
公共类可用性{
@规划变量(valueRangeProviderRefs={“timeGrainRange”})
私有时间粒度启动时间粒度;
@规划变量(valueRangeProviderRefs=“providerRange”)
私人供应商;
私人服务;
}
@规划解决方案
公共类任命可用性{
@ValueRangeProvider(id=“timeGrainRange”)
@问题FactCollectionProperty
私有列表时间粒度列表;
@问题FactCollectionProperty
@ValueRangeProvider(id=“providerRange”)
私人名单提供者名单;
@问题FactCollectionProperty
@ValueRangeProvider(id=“任命范围”)
私人名单任命名单;
@PlanningEntityCollectionProperty
私有列表可用性列表;
@计划分数
私人硬媒体软件评分;
}
由于我是optaplanner的新手,您能告诉我这是否是一条可行的道路吗


更新1:出于设计目的,我已将问题简化到最低程度。

请查看
optaplanner示例
中的会议日程安排示例,了解如何对其建模。另请参见设计模式部分文档中的时间粒度模式。学校时间表快速启动遵循时隙模式


非常感谢您的帮助,这将自动为客户分配可用的时间段,我希望能够为用户显示给定日期和给定服务的可用时间段,然后客户将选择,预订将保存到数据库中,而且相应的时间段将不再提供给任何其他人。顺便问一下,预订系统是optaplanner的一个好用例吗?如果日期是固定的,列出服务和/或首选员工,那么问题是按员工查找可用的时间段,以向客户展示,尽量减少服务之间的延迟,确保不在节假日选择员工,再次感谢您的帮助当且仅当您可以在同一solve()调用中分配多个预订时,预订系统是optaplanner的一个很好的用例。如果您需要为每个solve()调用分配一个预订,例如,如果客户机调用预订,请给出他们的约束条件,并需要立即知道预订的时间,那么optaplanner就太过分了。如果除1个预订之外的所有预订都被锁定,那么就不会获得巨大的优化收益。在这种情况下,一个简单的决策表(参见drools)就可以了。但在另一种情况下,optaplanner是完美的。是的,这是有道理的,但我有更复杂的业务规则,比如客户可以有多个服务,但两者之间的间隔应小于X分钟,或者一些服务可以并行完成,或者服务持续时间取决于员工?这是否证明可以使用optaplanner?显然,slover应该有一两秒钟的时间响应,因为它是实时的。你解决过这个问题吗?我也有同样的问题,我也在评估optaplanner。我最终没有使用optiplanner,只是一些算法,但如果你知道如何解决它,我很乐意讨论它。