Commit fd420b9d authored by 邬友楠's avatar 邬友楠

流程仿真

parent f35f1a14
Pipeline #149 failed with stages
...@@ -204,10 +204,10 @@ ...@@ -204,10 +204,10 @@
<groupId>org.apache.xmlbeans</groupId> <groupId>org.apache.xmlbeans</groupId>
<artifactId>xmlbeans</artifactId> <artifactId>xmlbeans</artifactId>
</dependency> </dependency>
<dependency> <!--<dependency>
<groupId>xerces</groupId> <groupId>xerces</groupId>
<artifactId>xercesImpl</artifactId> <artifactId>xercesImpl</artifactId>
</dependency> </dependency>-->
<!-- Microsoft Office格式档案读和写 --> <!-- Microsoft Office格式档案读和写 -->
<dependency> <dependency>
<groupId>org.apache.poi</groupId> <groupId>org.apache.poi</groupId>
......
...@@ -7,6 +7,7 @@ import desmoj.core.simulator.SimProcess; ...@@ -7,6 +7,7 @@ import desmoj.core.simulator.SimProcess;
/** /**
* @Author: wuyounan * @Author: wuyounan
* @Date: 2021/4/25 0025 上午 11:48 * @Date: 2021/4/25 0025 上午 11:48
* 申请人 流程
*/ */
public class Applicant extends SimProcess { public class Applicant extends SimProcess {
......
...@@ -10,6 +10,7 @@ import java.util.concurrent.TimeUnit; ...@@ -10,6 +10,7 @@ import java.util.concurrent.TimeUnit;
/** /**
* @Author: wuyounan * @Author: wuyounan
* @Date: 2021/4/25 0025 下午 4:21 * @Date: 2021/4/25 0025 下午 4:21
* 申请人生成器
*/ */
public class ApplicantGenerator extends SimProcess { public class ApplicantGenerator extends SimProcess {
...@@ -23,7 +24,7 @@ public class ApplicantGenerator extends SimProcess { ...@@ -23,7 +24,7 @@ public class ApplicantGenerator extends SimProcess {
int cont = 0; int cont = 0;
while(true){ while(true){
int interarrivalTime = (int) model.getInterArrivalTime(model.presentTime().getTimeAsDouble()); int interarrivalTime = (int) model.getInterArrivalTime(model.presentTime().getTimeAsDouble());
System.out.println("生成器"+cont+"到达时间:"+ interarrivalTime); System.out.println("申请人"+cont+"申请时间:"+ interarrivalTime);
//wait for interarrival //wait for interarrival
this.hold(new TimeSpan(interarrivalTime, TimeUnit.MINUTES)); this.hold(new TimeSpan(interarrivalTime, TimeUnit.MINUTES));
//create new patient and activate him/her //create new patient and activate him/her
......
...@@ -3,6 +3,7 @@ package com.huigou.desmoj; ...@@ -3,6 +3,7 @@ package com.huigou.desmoj;
/** /**
* @Author: wuyounan * @Author: wuyounan
* @Date: 2021/4/26 0026 上午 8:20 * @Date: 2021/4/26 0026 上午 8:20
* 业务流程定义
*/ */
public class BusinessProcess { public class BusinessProcess {
/** /**
......
package com.huigou.desmoj; package com.huigou.desmoj;
import com.huigou.desmoj.domain.model.ProcessSimulation;
import desmoj.core.dist.BoolDistBernoulli;
import desmoj.core.dist.ContDistExponential; import desmoj.core.dist.ContDistExponential;
import desmoj.core.simulator.Experiment;
import desmoj.core.simulator.Model; import desmoj.core.simulator.Model;
import desmoj.core.simulator.ProcessQueue; import desmoj.core.simulator.ProcessQueue;
import desmoj.core.simulator.TimeInstant;
import org.springframework.util.Assert;
import java.util.HashMap;
import java.util.Map; import java.util.Map;
import java.util.List;
import java.util.concurrent.TimeUnit;
/** /**
* @Author: wuyounan * @Author: wuyounan
* @Date: 2021/4/25 0025 上午 11:29 * @Date: 2021/4/25 0025 上午 11:29
*/ */
public class ProcessModel extends Model { public class ProcessModel extends Model {
private Map<String,ProcessQueue<Applicant>> applicantProcessQueues; /**
private Map<String,ProcessQueue<Processors>> processorsProcessQueues; * 申请人等待节点列表
*/
private Map<String,ProcessQueue<Applicant>> applicantWaitingProcessQueues;
public Map<String, ProcessQueue<Applicant>> getApplicantWaitingProcessQueues() {
return applicantWaitingProcessQueues;
}
/**
* 各业务节点 处理人闲置列表
*/
private Map<String,ProcessQueue<Processors>> processorsIdleQueues;
public Map<String, ProcessQueue<Processors>> getProcessorsIdleQueues() {
return processorsIdleQueues;
}
/**
* 业务节点集合
*/
private Map<String,Processors> processorsMap;
/**
* 业务节点处理人人数
*/
private Map<String,Integer> processNumbers;
public Map<String, Integer> getProcessNumbers() {
return processNumbers;
}
/**
* 业务申请时间段
*/
private Map<String,ContDistExponential> processorsCommitDate; private Map<String,ContDistExponential> processorsCommitDate;
/**
* 各业务节点平均处理时间
*/
private Map<String,ContDistExponential> processingTimes;
/**
* 仿真流程配置
*/
private ProcessSimulation processSimulation;
// private List<> // private List<>
/** /**
* 业务发起时间段 上午8点-10点 * 业务发起时间段 上午8点-10点
...@@ -31,14 +79,13 @@ public class ProcessModel extends Model { ...@@ -31,14 +79,13 @@ public class ProcessModel extends Model {
* 业务发起时间段 下午4点-8点 * 业务发起时间段 下午4点-8点
*/ */
private ContDistExponential patientArrival4To8; private ContDistExponential patientArrival4To8;
/**
* 所需要的处理时间
*/
private ContDistExponential processingTime;
public ProcessModel(Model owner, String modelName, boolean showInReport, boolean showInTrace) { public ProcessModel(Model owner, String modelName,
boolean showInReport, boolean showInTrace,
ProcessSimulation processSimulation) {
super(owner, modelName, showInReport, showInTrace); super(owner, modelName, showInReport, showInTrace);
this.processSimulation = processSimulation;
} }
@Override @Override
...@@ -48,20 +95,22 @@ public class ProcessModel extends Model { ...@@ -48,20 +95,22 @@ public class ProcessModel extends Model {
@Override @Override
public void doInitialSchedules() { public void doInitialSchedules() {
processorsProcessQueues.forEach((key, value) -> { processSimulation.getProcessNodes().forEach((processNode) -> {
Processors processors = new Processors(this,key,true); Processors processors = new Processors(this,processNode.getName(),true);
processors.activate(); processors.activate();
processorsMap.put(processNode.getId(),processors);
}); });
ApplicantGenerator generator = new ApplicantGenerator(this,"申请人生成器",false);
generator.activate();
} }
@Override @Override
public void init() { public void init() {
processorsCommitDate.forEach((key,value) ->{
});
/** (Model owner, String name, double mean, boolean showInReport, boolean showInTrace)) /** (Model owner, String name, double mean, boolean showInReport, boolean showInTrace))
* owner 当前流程 name 描述(名称) mean 随机平均值 showInReport是否在报表显示,showInTrace 是否在追踪时显示 * owner 当前流程 name 描述(名称) mean 随机平均值 showInReport是否在报表显示,showInTrace 是否在追踪时显示
*/ */
processorsCommitDate = new HashMap<>();
patientArrival8To10 = new ContDistExponential(this, "早上发起", 15, true, false); patientArrival8To10 = new ContDistExponential(this, "早上发起", 15, true, false);
patientArrival10To1 = new ContDistExponential(this, "中午发起", 6, true, false); patientArrival10To1 = new ContDistExponential(this, "中午发起", 6, true, false);
patientArrival1To4 = new ContDistExponential(this, "下午发起", 6, true, false); patientArrival1To4 = new ContDistExponential(this, "下午发起", 6, true, false);
...@@ -70,6 +119,17 @@ public class ProcessModel extends Model { ...@@ -70,6 +119,17 @@ public class ProcessModel extends Model {
processorsCommitDate.put("patientArrival10To1",patientArrival10To1); processorsCommitDate.put("patientArrival10To1",patientArrival10To1);
processorsCommitDate.put("patientArrival1To4",patientArrival1To4); processorsCommitDate.put("patientArrival1To4",patientArrival1To4);
processorsCommitDate.put("patientArrival4To8",patientArrival4To8); processorsCommitDate.put("patientArrival4To8",patientArrival4To8);
processorsIdleQueues = new HashMap<>();
processingTimes = new HashMap<>();
processSimulation.getProcessNodes().forEach((processNode) -> {
ProcessQueue<Applicant> applicantWaitingProcessors = new ProcessQueue<Applicant>(this,"申请人等待【"+processNode.getName()+"】审核",true,true);
applicantWaitingProcessQueues.put(processNode.getId(),applicantWaitingProcessors);
ProcessQueue<Processors> processQueue = new ProcessQueue<Processors>(this,"【"+processNode.getName()+"】等待申请人",true,true);
processorsIdleQueues.put(processNode.getId(),processQueue);
ContDistExponential processServiceTime = new ContDistExponential(this,"【"+processNode.getName()+"】服务时间",processNode.getProcessingTime(),true,false);
processingTimes.put(processNode.getId(),processServiceTime);
processNumbers.put(processNode.getId(),processNode.getNumber());
});
} }
public double getInterArrivalTime(double time) { public double getInterArrivalTime(double time) {
...@@ -83,4 +143,74 @@ public class ProcessModel extends Model { ...@@ -83,4 +143,74 @@ public class ProcessModel extends Model {
return patientArrival4To8.sample(); return patientArrival4To8.sample();
} }
} }
public boolean isPass(Float passProbability){
BoolDistBernoulli isPass = new BoolDistBernoulli(this,"是否通过当前节点", passProbability, true, false);
return isPass.sample();
}
public static void main(String[] args) {
ProcessSimulation processSimulation = new ProcessSimulation();
processSimulation.setShowInReport(1);
processSimulation.setShowInTrace(1);
Assert.notNull(processSimulation,"未找到流程仿真配置信息!");
// 设置时间单位(分钟)
Experiment.setEpsilon(TimeUnit.MINUTES);
Experiment.setReferenceUnit(TimeUnit.MINUTES);
ProcessModel model = new ProcessModel(null,
processSimulation.getName(),
processSimulation.getShowInReport()==1,
processSimulation.getShowInTrace()==1,
processSimulation);
Experiment exp = new Experiment(processSimulation.getName()+"流程仿真");
model.connectToExperiment(exp);
// 设置试验参数
// 是否显示进度条
exp.setShowProgressBar(false);
TimeInstant runningTime = null;
TimeUnit timeType = TimeUnit.MINUTES;
if(processSimulation.getTimeType()==1){
runningTime = new TimeInstant(processSimulation.getRunningTime(),TimeUnit.MINUTES);
timeType = TimeUnit.MINUTES;
} if(processSimulation.getTimeType()==2){
runningTime = new TimeInstant(processSimulation.getRunningTime(),TimeUnit.HOURS);
timeType = TimeUnit.HOURS;
} if(processSimulation.getTimeType()==3){
timeType = TimeUnit.DAYS;
runningTime = new TimeInstant(processSimulation.getRunningTime(),TimeUnit.DAYS);
} else {
// 设置模拟结束时间 默认为720分钟,运行时间为12小时
runningTime = new TimeInstant(720, TimeUnit.MINUTES);
}
exp.stop(runningTime);
// 设置跟踪和调试的周期
exp.tracePeriod(new TimeInstant(0, timeType), runningTime);
exp.debugPeriod(new TimeInstant(0, timeType), runningTime);
// 在模拟时间0.0开始实验
exp.start();
model.getProcessorsIdleQueues().forEach((key,idleQueue) ->{
if (idleQueue.length()!= model.getProcessNumbers().get(key)){
System.out.println("办理已时间结束,请找其他【"+idleQueue.getDescription()+"】");
}
});
model.getApplicantWaitingProcessQueues().forEach((key,applicantWaitingProcess) ->{
while (!applicantWaitingProcess.isEmpty()){
System.out.println("业务办理时间已结束,办理环节【"+applicantWaitingProcess.getDescription()+"】");
}
});
// 生成报告(和其他输出文件)
exp.report();
// 停止所有仍然活着的线程,关闭所有输出文件
exp.finish();
}
} }
...@@ -3,13 +3,17 @@ package com.huigou.desmoj; ...@@ -3,13 +3,17 @@ package com.huigou.desmoj;
import co.paralleluniverse.fibers.SuspendExecution; import co.paralleluniverse.fibers.SuspendExecution;
import desmoj.core.simulator.Model; import desmoj.core.simulator.Model;
import desmoj.core.simulator.SimProcess; import desmoj.core.simulator.SimProcess;
import lombok.Data;
/** /**
* @Author: wuyounan * @Author: wuyounan
* @Date: 2021/4/25 0025 上午 11:41 * @Date: 2021/4/25 0025 上午 11:41
* 处理人 流程生命周期
*/ */
public class Processors extends SimProcess { public class Processors extends SimProcess {
private Boolean isPass;
public Processors(Model owner, String name, boolean showInTrace){ public Processors(Model owner, String name, boolean showInTrace){
super(owner, name, showInTrace); super(owner, name, showInTrace);
} }
...@@ -19,4 +23,12 @@ public class Processors extends SimProcess { ...@@ -19,4 +23,12 @@ public class Processors extends SimProcess {
ProcessModel processModel = (ProcessModel) this.getModel(); ProcessModel processModel = (ProcessModel) this.getModel();
} }
public Boolean getPass() {
return isPass;
}
public void setPass(Boolean pass) {
isPass = pass;
}
} }
package com.huigou.desmoj.application;
import com.huigou.desmoj.domain.model.ProcessSimulation;
import com.huigou.desmoj.domain.query.ProcessSimulationQuery;
import java.util.List;
import java.util.Map;
/**
* @Author: wuyounan
* @Date: 2021/5/5 0005 下午 7:17
*/
public interface ProcessSimulationApplication {
/**
* 分页查询流程仿真配置
* @param query
* @return
*/
Map<String, Object> slicedQuery(ProcessSimulationQuery query);
/**
* 根据流程仿真ID查询流程仿真配置
* @param id
* @return
*/
ProcessSimulation loadByID(String id);
/**
* 运行流程仿真实例
* @param id
*/
void runProcessSimulation(String id);
}
package com.huigou.desmoj.application.impl;
import com.huigou.desmoj.ProcessModel;
import com.huigou.desmoj.application.ProcessSimulationApplication;
import com.huigou.desmoj.domain.model.ProcessSimulation;
import com.huigou.desmoj.domain.query.ProcessSimulationQuery;
import com.huigou.desmoj.repository.ProcessSimulationRepository;
import desmoj.core.simulator.Experiment;
import desmoj.core.simulator.TimeInstant;
import org.springframework.stereotype.Service;
import org.springframework.util.Assert;
import java.util.Iterator;
import java.util.Map;
import java.util.concurrent.TimeUnit;
/**
* @Author: wuyounan
* @Date: 2021/5/5 0005 下午 7:17
*/
@Service
public class ProcessSimulationApplicationImpl implements ProcessSimulationApplication {
private ProcessSimulationRepository processSimulationRepository;
@Override
public Map<String, Object> slicedQuery(ProcessSimulationQuery query) {
return null;
}
@Override
public ProcessSimulation loadByID(String id) {
return processSimulationRepository.getOne(id);
}
@Override
public void runProcessSimulation(String id) {
ProcessSimulation processSimulation = processSimulationRepository.findOne(id);
Assert.isNull(processSimulation,"未找到流程仿真配置信息!");
// 设置时间单位(分钟)
Experiment.setEpsilon(TimeUnit.MINUTES);
Experiment.setReferenceUnit(TimeUnit.MINUTES);
ProcessModel model = new ProcessModel(null,
processSimulation.getName(),
processSimulation.getShowInReport()==1,
processSimulation.getShowInTrace()==1,
processSimulation);
Experiment exp = new Experiment(processSimulation.getName()+"流程仿真");
model.connectToExperiment(exp);
// 设置试验参数
// 是否显示进度条
exp.setShowProgressBar(false);
TimeInstant runningTime = null;
TimeUnit timeType = TimeUnit.MINUTES;
if(processSimulation.getTimeType()==1){
runningTime = new TimeInstant(processSimulation.getRunningTime(),TimeUnit.MINUTES);
timeType = TimeUnit.MINUTES;
} if(processSimulation.getTimeType()==2){
runningTime = new TimeInstant(processSimulation.getRunningTime(),TimeUnit.HOURS);
timeType = TimeUnit.HOURS;
} if(processSimulation.getTimeType()==3){
timeType = TimeUnit.DAYS;
runningTime = new TimeInstant(processSimulation.getRunningTime(),TimeUnit.DAYS);
} else {
// 设置模拟结束时间 默认为720分钟,运行时间为12小时
runningTime = new TimeInstant(720, TimeUnit.MINUTES);
}
exp.stop(runningTime);
// 设置跟踪和调试的周期
exp.tracePeriod(new TimeInstant(0, timeType), runningTime);
exp.debugPeriod(new TimeInstant(0, timeType), runningTime);
// 在模拟时间0.0开始实验
exp.start();
model.getProcessorsIdleQueues().forEach((key,idleQueue) ->{
if (idleQueue.length()!= model.getProcessNumbers().get(key)){
System.out.println("办理已时间结束,请找其他【"+idleQueue.getDescription()+"】");
}
});
model.getApplicantWaitingProcessQueues().forEach((key,applicantWaitingProcess) ->{
while (!applicantWaitingProcess.isEmpty()){
System.out.println("业务办理时间已结束,办理环节【"+applicantWaitingProcess.getDescription()+"】");
}
});
// 生成报告(和其他输出文件)
exp.report();
// 停止所有仍然活着的线程,关闭所有输出文件
exp.finish();
}
}
package com.huigou.desmoj.controller; package com.huigou.desmoj.controller;
import com.huigou.desmoj.application.ProcessSimulationApplication;
import com.huigou.uasp.annotation.ControllerMapping; import com.huigou.uasp.annotation.ControllerMapping;
import com.huigou.uasp.client.CommonController; import com.huigou.uasp.client.CommonController;
import com.huigou.uasp.exception.PageForwardException; import com.huigou.uasp.exception.PageForwardException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller; import org.springframework.stereotype.Controller;
/** /**
...@@ -13,6 +15,9 @@ import org.springframework.stereotype.Controller; ...@@ -13,6 +15,9 @@ import org.springframework.stereotype.Controller;
@ControllerMapping("processModel") @ControllerMapping("processModel")
public class ProcessModelController extends CommonController { public class ProcessModelController extends CommonController {
@Autowired
private ProcessSimulationApplication processSimulationApplication;
@Override @Override
protected String getPagePath() { protected String getPagePath() {
return "/desmoj/"; return "/desmoj/";
...@@ -28,6 +33,7 @@ public class ProcessModelController extends CommonController { ...@@ -28,6 +33,7 @@ public class ProcessModelController extends CommonController {
public String fowardDemoRun() { public String fowardDemoRun() {
// return this.getRequest().getRequestDispatcher("").forward(this.getRequest(), this.getResponse()); // return this.getRequest().getRequestDispatcher("").forward(this.getRequest(), this.getResponse());
return ""; processSimulationApplication.runProcessSimulation("sdfsd");
return success();
} }
} }
package com.huigou.desmoj.domain.model;
import com.huigou.data.domain.model.AbstractEntity;
import lombok.Data;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Table;
/**
* @Author: wuyounan
* @Date: 2021/5/5 0005 下午 6:59
*/
@Data
@Entity
@Table(name = "SIM_PROCESS_NODE")
public class ProcessNode extends AbstractEntity {
/**
* 仿真流程ID
*/
@Column(name = "SIM_PROCESS_ID")
private String simProcessId;
/**
* 节点名称
*/
@Column(name = "NAME")
private String name;
/**
* 节点处理人数
*/
@Column(name = "NUMBER")
private Integer number;
/**
* 平均处理时间(MIN分钟)
*/
@Column(name = "PROCESSING_TIME")
private Long processingTime;
/**
* 通过,下一节点
*/
@Column(name = "PASS_NEXT_NODE_ID")
private String passNextNodeId;
/**
* 不通过,下一节点
*/
@Column(name = "NO_PASS_NEXT_NODE_ID")
private String noPassNextNodeId;
/**
* 通过概率
*/
@Column(name = "PASS_PROBABILITY")
private Float passProbability;
/**
* 节点类型1:开始节点,50:中间节点,100:结束节点
*/
private Integer nodeType;
}
package com.huigou.desmoj.domain.model;
import com.huigou.data.domain.model.AbstractEntity;
import lombok.Data;
import javax.persistence.*;
import java.util.List;
/**
* @Author: wuyounan
* @Date: 2021/5/5 0005 下午 6:46
* 流程仿真对象
*/
@Data
@Entity
@Table(name = "SIM_PROCESS_SIMULATION")
public class ProcessSimulation extends AbstractEntity {
/**
* 流程名称
*/
@Column(name = "NAME")
private String name;
/**
* 备注
*/
@Column(name = "REMARK")
private String remark;
@OneToMany
@JoinColumn(name = "SIM_PROCESS_ID")
private List<ProcessNode> processNodes;
/**
* 是否在报表中显示
*/
@Column(name = "SHOW_IN_REPORT")
private Integer showInReport;
/**
* 是否在跟踪中显示
*/
@Column(name = "SHOW_IN_TRACE")
private Integer showInTrace;
/**
* 运行时间(模拟结束时间)
*/
@Column(name = "RUNNING_TIME")
private Long runningTime;
/**
* 时间类型:1:MIN(分钟)
*/
private Integer timeType;
}
package com.huigou.desmoj.domain.query;
import lombok.Data;
/**
* @Author: wuyounan
* @Date: 2021/5/5 0005 下午 7:20
*/
@Data
public class ProcessSimulationQuery {
private String name;
private Integer status;
}
package com.huigou.desmoj.repository;
import com.huigou.desmoj.domain.model.ProcessNode;
import org.springframework.data.jpa.repository.JpaRepository;
/**
* @Author: wuyounan
* @Date: 2021/5/5 0005 下午 7:12
*/
public interface ProcessNodeRepository extends JpaRepository<ProcessNode,String> {
}
package com.huigou.desmoj.repository;
import com.huigou.desmoj.domain.model.ProcessSimulation;
import org.springframework.data.jpa.repository.JpaRepository;
/**
* @Author: wuyounan
* @Date: 2021/5/5 0005 下午 7:14
*/
public interface ProcessSimulationRepository extends JpaRepository<ProcessSimulation,String> {
}
...@@ -345,7 +345,7 @@ ...@@ -345,7 +345,7 @@
<dependency> <dependency>
<groupId>org.projectlombok</groupId> <groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId> <artifactId>lombok</artifactId>
<version>1.18.12</version> <version>1.18.20</version>
</dependency> </dependency>
</dependencies> </dependencies>
<build> <build>
......
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