Commit 19ed1274 sunke

料架分配逻辑修改

1 个父辈 423c514e
package com.myproject.bean.qisda; package com.myproject.bean.qisda;
import com.myproject.bean.update.DataLog;
import com.myproject.util.StorageConstants; import com.myproject.util.StorageConstants;
import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.Logger;
...@@ -40,6 +41,19 @@ public class ShelfInfo { ...@@ -40,6 +41,19 @@ public class ShelfInfo {
} }
/** /**
* F料架最多放26个小料
*/
private static int MAX_F_SMALL_NUM = 26;
/**
* F料架1-26放小料, 27-31放大料
* @return
*/
public static ShelfInfo newFShelf(){
return new ShelfInfo(StorageConstants.SHEFL_TYPE.F,31);
}
/**
* 需求单号 * 需求单号
*/ */
private String hSerial; private String hSerial;
...@@ -93,12 +107,7 @@ public class ShelfInfo { ...@@ -93,12 +107,7 @@ public class ShelfInfo {
return emptyLocCount; return emptyLocCount;
} }
/**
* 库位数
*/
public int getUsedLocCount(){
return locMap.size();
}
public void setLocMap(Map<Integer, ShelfLoc> locMap) { public void setLocMap(Map<Integer, ShelfLoc> locMap) {
this.locMap = locMap; this.locMap = locMap;
...@@ -131,6 +140,29 @@ public class ShelfInfo { ...@@ -131,6 +140,29 @@ public class ShelfInfo {
} }
/** /**
* 是否到达可放小料的最大数量,F料架1-26放小料, 27-31放大料
*/
public boolean reachMaxSmallLoc(){
int smallCount = 0;
for (ShelfLoc loc : locMap.values()) {
if(loc.getLoc() <= MAX_F_SMALL_NUM){
smallCount++;
}
}
return smallCount >= MAX_F_SMALL_NUM;
}
public boolean reachMaxBigLoc(){
int bigCount = 0;
for (ShelfLoc loc : locMap.values()) {
if(loc.getLoc() > MAX_F_SMALL_NUM){
bigCount++;
}
}
return bigCount >= maxLocCount - MAX_F_SMALL_NUM;
}
/**
* 料架是否放满 * 料架是否放满
*/ */
public boolean isFull(){ public boolean isFull(){
...@@ -222,14 +254,13 @@ public class ShelfInfo { ...@@ -222,14 +254,13 @@ public class ShelfInfo {
/** /**
* 为补料取消一个库位 * 为补料取消一个库位
*/ */
public boolean cancelLoc(String rfidType, String barcode){ public boolean cancelLoc(String rfidType, DataLog task){
if(rfidType.equals(this.getShelfType())){ if(rfidType.equals(this.getShelfType())){
int usedCount = getUsedLocCount(); for(int i=maxLocCount; i> 0; i--){
for(int i=usedCount; i> 0; i--){
ShelfLoc shelfLoc = locMap.get(i); ShelfLoc shelfLoc = locMap.get(i);
if(shelfLoc != null && shelfLoc.isEmpty() && !shelfLoc.isLock()){ if(shelfLoc != null && shelfLoc.isEmpty() && !shelfLoc.isLock() && shelfLoc.getReelType() == task.getReelType()){
//未放过料,且未锁定 //未放过料,且未锁定
shelfLoc.putIn(barcode); shelfLoc.putIn(task.getBarcode());
return true; return true;
} }
} }
...@@ -299,176 +330,75 @@ public class ShelfInfo { ...@@ -299,176 +330,75 @@ public class ShelfInfo {
} }
/** /**
* 为包装料锁定架位
* @param shelfLoc 架位信息
* @param packageReelId 包装料条码
* @return
*/
public boolean lockForPackage(ShelfLoc shelfLoc, String packageReelId){
ShelfLoc emptyLoc = locMap.get(shelfLoc.getLoc());
if(!emptyLoc.isEmpty()){
log.info("为包装料["+packageReelId+"]锁定C型料架"+tempRfid()+"["+shelfLoc.getLoc()+"]失败,位置为不空");
return false;
}
log.info("为包装料["+packageReelId+"]锁定架位"+tempRfid()+"["+shelfLoc.getLoc()+"]");
emptyLoc.setBarcode(packageReelId);
return true;
}
/**
* 为不需要按顺序摆放的料盘锁定一个架位,如果已经锁定过,返回对应的架位 * 为不需要按顺序摆放的料盘锁定一个架位,如果已经锁定过,返回对应的架位
*/ */
public ShelfLoc lockOneEmptyLoc(String barcode, int reelType, String robotIndex){ public ShelfLoc lockOneEmptyLoc(DataLog task){
//if(rfid.contains(shelfType)) {
//不是同一种料架的忽略
//先看看此条码是否已经锁定过 //先看看此条码是否已经锁定过
for (ShelfLoc shelfLoc : locMap.values()) { for (ShelfLoc shelfLoc : locMap.values()) {
if(shelfLoc.isLock() && shelfLoc.getBarcode().equals(barcode)){ if(shelfLoc.isLock() && shelfLoc.getBarcode().equals(task.getBarcode())){
log.info("找到条码["+barcode+"]锁定的架位["+shelfLoc.getLoc()+"]"); log.info("找到条码["+task.getBarcode()+"]锁定的架位["+shelfLoc.getLoc()+"]");
return shelfLoc;
}
}
int usedCount = getUsedLocCount();
//1号机器人从大到小, 2号机器人从小到大,且71,72,73位不分配给2号机器人
if(robotIndex.equals("1")){
//1号机器人优先放70,71,72三个位置
ShelfLoc shelfLoc = lockLocation(72,barcode,reelType);
if(shelfLoc == null){
shelfLoc = lockLocation(71,barcode,reelType);
if(shelfLoc == null){
shelfLoc = lockLocation(70,barcode,reelType);
}
}
if(shelfLoc == null){
for(int i=usedCount; i> 0; i--){
//大料12号位不分配给1号机器人
if(StorageConstants.SHEFL_TYPE.isCShelf(shelfType)){
if(i == 12){
continue;
}
}
shelfLoc = lockLocation(i,barcode,reelType);
if(shelfLoc != null){
return shelfLoc;
}
}
}
if(shelfLoc == null && StorageConstants.SHEFL_TYPE.isCShelf(shelfType)){
//如果执行到这里还有空,说明另一个机器人停掉了只能分配了
for(int i=usedCount; i> 0; i--){
shelfLoc = lockLocation(i,barcode,reelType);
if(shelfLoc != null){
return shelfLoc;
}
}
}
return shelfLoc;
}else if(robotIndex.equals("2")){
ShelfLoc shelfLoc = null;
if(StorageConstants.SHEFL_TYPE.isCShelf(shelfType)){
//大料12号位分给2号机器人
shelfLoc = lockLocation(12,barcode,reelType);
}
if(shelfLoc == null){
for(int i=1; i<= usedCount; i++){
//小料70,71,72位不分配给2号机器人
if(StorageConstants.SHEFL_TYPE.isDShelf(shelfType)){
if(i==70 || i == 71 || i==72){
continue;
}
}
shelfLoc = lockLocation(i,barcode,reelType);
if(shelfLoc != null){
return shelfLoc; return shelfLoc;
} }
} }
}
if(shelfLoc == null && StorageConstants.SHEFL_TYPE.isDShelf(shelfType)){ for(int i=1; i<= maxLocCount; i++){
//如果执行到这里还有空,说明另一个机器人停掉了只能分配了 ShelfLoc shelfLoc = lockLocation(i,task);
for(int i=usedCount; i> 0; i--){
shelfLoc = lockLocation(i,barcode,reelType);
if(shelfLoc != null){
return shelfLoc;
}
}
}
return shelfLoc;
}else {
//包装料
for(int i=1; i<= usedCount; i++){
ShelfLoc shelfLoc = lockLocation(i,barcode,reelType);
if(shelfLoc != null){ if(shelfLoc != null){
return shelfLoc; return shelfLoc;
} }
} }
}
//}
return null; return null;
} }
/** /**
* 锁定库位,如果成功返回库位,如果失败返回null * 锁定库位,如果成功返回库位,如果失败返回null
*/ */
private ShelfLoc lockLocation(int loc,String barcode, int reelType){ private ShelfLoc lockLocation(int loc, DataLog task){
ShelfLoc shelfLoc = locMap.get(loc); ShelfLoc shelfLoc = locMap.get(loc);
if(shelfLoc != null && shelfLoc.isEmpty() && !shelfLoc.isLock()){ if(shelfLoc != null && shelfLoc.isEmpty() && !shelfLoc.isLock() && task.getReelType() == shelfLoc.getReelType()){
log.info("为[" + barcode + "]锁定架位"+tempRfid() + "["+loc+"]"); log.info("为[" + task.getBarcode() + "]锁定架位"+tempRfid() + "["+loc+"]");
//未放过料,且未锁定 //未放过料,且未锁定
shelfLoc.setBarcode(barcode); shelfLoc.setBarcode(task.getBarcode());
shelfLoc.setReelType(reelType); shelfLoc.setReelType(task.getReelType());
locMap.put(loc, shelfLoc); locMap.put(loc, shelfLoc);
return shelfLoc; return shelfLoc;
} }
return null; return null;
} }
/**
* 添加缺料空位
*/
public int addEmptyLoc(){
return addShelfLoc(null, 0);
}
/** /**
* 添加一个库位 * 添加一个库位
*/ */
public int addLimitLoc(String barcode, int reelType){ public int addUnLimitLoc(DataLog task){
if(barcode == null){
barcode = "";
}
return addShelfLoc(barcode, reelType);
}
/**
* 添加一个库位,库位固定放某个条码,不限制库位时,设为空字符串,缺料库位设置为null
* @param barcode
*/
private int addShelfLoc(String barcode, int reelType){
for(int i=1; i<= maxLocCount; i++){ for(int i=1; i<= maxLocCount; i++){
ShelfLoc shelfLoc = locMap.get(i); ShelfLoc shelfLoc = locMap.get(i);
if(shelfLoc == null){ if(shelfLoc == null){
shelfLoc = new ShelfLoc(); boolean addThis = false;
if(barcode == null){ if(task.isSmallReel()){
barcode = "no code"; if(i<= MAX_F_SMALL_NUM){
shelfLoc.setEmpty(false); addThis = true;
}
}else{
if(i> MAX_F_SMALL_NUM){
addThis = true;
} }
}
if(addThis){
shelfLoc = new ShelfLoc();
shelfLoc.setLoc(i); shelfLoc.setLoc(i);
shelfLoc.setBarcode(barcode); shelfLoc.setBarcode("");
shelfLoc.setReelType(reelType); shelfLoc.setReelType(task.getReelType());
locMap.put(i, shelfLoc); locMap.put(i, shelfLoc);
return i; return i;
} }
} }
}
return -1; return -1;
} }
public int getMaxLocCount() { public int getMaxLocCount() {
return maxLocCount; return maxLocCount;
} }
......
...@@ -575,9 +575,7 @@ public class DataLog extends BaseMongoBean /*implements Comparable<DataLog>*/ { ...@@ -575,9 +575,7 @@ public class DataLog extends BaseMongoBean /*implements Comparable<DataLog>*/ {
* @return * @return
*/ */
public int getReelType(){ public int getReelType(){
if(isPackageReel()){ if(isSmallReel()){
return StorageConstants.REEL_TYPE.PACKAGE;
}else if(isSmallReel()){
return StorageConstants.REEL_TYPE.SMALL; return StorageConstants.REEL_TYPE.SMALL;
}else{ }else{
return StorageConstants.REEL_TYPE.BIG; return StorageConstants.REEL_TYPE.BIG;
......
...@@ -203,76 +203,9 @@ public final class DateUtil { ...@@ -203,76 +203,9 @@ public final class DateUtil {
} }
public static void main(String args[]) throws Exception { public static void main(String args[]) throws Exception {
List<DataLog> list = new ArrayList<>();
list.add(newDataLog(14,2000));
list.add(newDataLog(14,4000));
list.add(newDataLog(2,3000));
list.add(newDataLog(2,1000));
list.add(newDataLog(2,2000));
list.add(newDataLog(2,4000));
list.add(newDataLog(3,2000));
list.add(newDataLog(1,1000));
list.add(newDataLog(1,2000));
list.add(newDataLog(1,3000));
List<DataLog> sortList = sortTailTasks(list);
sortList.sort(new Comparator<DataLog>() {
@Override
public int compare(DataLog o1, DataLog o2) {
return o1.getOutOrder() - o2.getOutOrder();
}
});
for (DataLog d : sortList) {
System.out.println("["+d.getOutOrder()+"]" +d.getAppendInfo().getSlotIndex()+ " - " + d.getNum());
}
} }
/**
* 对补料任务进行出库排序
*/
private static List<DataLog> sortTailTasks(List<DataLog> tailTasks){
Multimap<Integer,DataLog> slotTaskMap = HashMultimap.create();
Set<Integer> slotSet = new HashSet<>();
for (DataLog dataLog : tailTasks) {
slotTaskMap.put(dataLog.getAppendInfo().getSlotIndex(), dataLog);
slotSet.add(dataLog.getAppendInfo().getSlotIndex());
}
List<DataLog> sortList = new ArrayList<>();
int outOrder = 0;
while(outOrder < tailTasks.size()){
for (Integer slot : slotSet) {
Collection<DataLog> slotTasks = slotTaskMap.get(slot);
DataLog maxNumtask = null;
for (DataLog slotTask : slotTasks) {
if(maxNumtask == null || slotTask.getNum() > maxNumtask.getNum()){
maxNumtask = slotTask;
}
}
if(maxNumtask != null){
outOrder = outOrder + 1;
maxNumtask.setOutOrder(outOrder);
sortList.add(maxNumtask);
slotTaskMap.remove(slot,maxNumtask);
}
}
}
return sortList;
}
private static DataLog newDataLog(int slotIndex, int num){
DataLog d1 = new DataLog();
AppendInfo appendInfo = new AppendInfo();
appendInfo.setSlotIndex(slotIndex);
d1.setAppendInfo(appendInfo);
d1.setNum(num);
return d1;
}
} }
...@@ -645,6 +645,11 @@ public class StorageConstants { ...@@ -645,6 +645,11 @@ public class StorageConstants {
public static String E = "E"; public static String E = "E";
/** /**
* F料架1-26放小料, 27-31放大料
*/
public static String F = "F";
/**
* 带包装料架 * 带包装料架
*/ */
public static boolean isAShelf(String type){ public static boolean isAShelf(String type){
...@@ -668,6 +673,12 @@ public class StorageConstants { ...@@ -668,6 +673,12 @@ public class StorageConstants {
public static boolean isDShelf(String type){ public static boolean isDShelf(String type){
return judgeType(type, D); return judgeType(type, D);
} }
/**
* 混合料架
*/
public static boolean isFShelf(String type){
return judgeType(type, F);
}
public static boolean judgeType(String type, String targetType){ public static boolean judgeType(String type, String targetType){
if(type != null && type.contains(targetType)){ if(type != null && type.contains(targetType)){
......
...@@ -29,10 +29,6 @@ ...@@ -29,10 +29,6 @@
</content> </content>
<orderEntry type="inheritedJdk" /> <orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" /> <orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" name="Maven: org.springframework.data:spring-data-mongodb:1.8.0.RELEASE" level="project" />
<orderEntry type="library" name="Maven: org.mongodb:mongo-java-driver:2.12.5" level="project" />
<orderEntry type="library" scope="RUNTIME" name="Maven: org.slf4j:jcl-over-slf4j:1.7.11" level="project" />
<orderEntry type="library" name="Maven: org.springframework.data:spring-data-commons:1.10.2.RELEASE" level="project" />
<orderEntry type="library" name="Maven: commons-lang:commons-lang:2.6" level="project" /> <orderEntry type="library" name="Maven: commons-lang:commons-lang:2.6" level="project" />
<orderEntry type="library" name="Maven: org.springframework:spring-orm:4.1.6.RELEASE" level="project" /> <orderEntry type="library" name="Maven: org.springframework:spring-orm:4.1.6.RELEASE" level="project" />
<orderEntry type="library" name="Maven: org.springframework:spring-beans:4.1.6.RELEASE" level="project" /> <orderEntry type="library" name="Maven: org.springframework:spring-beans:4.1.6.RELEASE" level="project" />
......
...@@ -30,6 +30,7 @@ ...@@ -30,6 +30,7 @@
<build> <build>
<finalName>smdbox</finalName>
<defaultGoal>install</defaultGoal> <defaultGoal>install</defaultGoal>
<plugins> <plugins>
<plugin> <plugin>
......
支持 Markdown 格式
你添加了 0 到此讨论。请谨慎行事。
Finish editing this message first!