Commit cd22f5cc authored by Tong Li's avatar Tong Li

增加全局变量类

parent 0cfb29ea
package com.aps.entity.basic;
import lombok.Data;
/**
* 作者:佟礼
* 时间:2025-11-21
*/
@Data
public class GlobalParam {
/// <summary>
/// 是否可以打破优先级
/// </summary>
public static boolean IsBreakPriority = false;
/// <summary>
/// 是否多台设备
/// </summary>
public static boolean IsMultipleMachine = false;
/// <summary>
/// 是否重叠
/// </summary>
public static boolean IsOverlap = false;
}
package com.aps.service.Algorithm;
import com.aps.entity.basic.ScheduleChromosome;
/**
* 作者:佟礼
* 时间:2025-11-21
*/
public class GeneticAlgorithm {
public void Run() {
System.out.println("");
}
}
...@@ -90,6 +90,72 @@ public class PlanResultService { ...@@ -90,6 +90,72 @@ public class PlanResultService {
} }
} }
public List<ScheduleChromosome> execute1() {
try {
// 1. 读取数据
List<Machine> machines = loadData("machines.json", Machine.class);
List<Product> products = loadData("products.json", Product.class);
List<Order> orders = loadData("orders.json", Order.class);
// 设置机器信息到班次中
for (Machine machine : machines) {
if (machine.getShifts() != null) {
for (Shift shift : machine.getShifts()) {
shift.setMachineId(machine.getId());
shift.setMachineName(machine.getName());
}
}
// 调试:打印机器和班次信息
System.out.println("Machine: " + machine.getId() + ", Name: " + machine.getName());
if (machine.getShifts() != null) {
for (Shift shift : machine.getShifts()) {
System.out.println(" Shift: " + shift.getStartTime() + " - " + shift.getEndTime() +
", Status: " + shift.getStatus() +
", MachineId: " + shift.getMachineId() +
", MachineName: " + shift.getMachineName());
}
}
}
// 创建节假日
List<Holiday> holidays = Arrays.asList(
new Holiday(LocalDateTime.of(2025, 10, 1, 0, 0),
LocalDateTime.of(2025, 10, 7, 23, 59))
);
// 将节假日添加到所有设备中
addHolidaysToAllMachines(machines, holidays);
// 3. 创建调度服务
MachineSchedulerService machineScheduler = new MachineSchedulerService(
holidays, LocalDateTime.of(2025, 10, 1, 0, 0, 0));
// 4. 初始化机器时间线
for (Machine machine : machines) {
MachineTimeline timeline = machineScheduler.getOrCreateTimeline(machine);
machine.setAvailability(timeline.getSegments());
}
// 5. 执行调度算法
AlgorithmScheduler7 scheduler = new AlgorithmScheduler7(products, machines, orders, machineScheduler);
List<ScheduleChromosome> scheduleChromosomes = scheduler.RunAll();
// 对调度结果按照 fitness 由高到低排序
scheduleChromosomes.sort((c1, c2) -> Double.compare(c2.getFitness(), c1.getFitness()));
// 为每个 ScheduleChromosome 分配场景ID(基于排序后的位置)
for (int i = 0; i < scheduleChromosomes.size(); i++) {
scheduleChromosomes.get(i).setSceneId(i + 1); // 场景ID从1开始
}
return scheduleChromosomes;
} catch (Exception e) {
throw new RuntimeException("调度执行失败", e);
}
}
/** /**
* 加载数据,优先从上传文件夹加载,如果不存在则从resources加载 * 加载数据,优先从上传文件夹加载,如果不存在则从resources加载
* *
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment