自动化立体仓库 - WMS系统
#
lsh
2024-06-13 36f65326878da5e07d17453ce35681c7337ce8b5
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
package com.zy.common.model;
 
import com.alibaba.fastjson.JSON;
import com.core.common.Arith;
import com.core.exception.CoolException;
 
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
 
/**
 * <strong>立库货架实体类</strong>
 * Created by vincent on 2020/6/11
 */
public class Shelves {
 
    // 货架排数量
    public final int size;
 
    // 货架组数量
    public final int group;
 
    // 偏移量[default:0]
    public final int offset;
 
    // 货架实例节点集合
    public List<List<Integer>> nodes;
 
    public Shelves(int size, int group) {
        this(size, group, 0);
    }
 
    /**
     * @param size 货架单排总数
     * @param group 货架组数量
     * @param offset 序列号偏移量
     */
    public Shelves(int size, int group, int offset) {
        this.size = size;
        this.group = group;
        this.offset = offset-1;
        init();
    }
 
 
 
    /**
     * 初始化方法【私有】
     */
    private void init(){
        if (group == 0 || size%group != 0) {
            throw new RuntimeException("shelves init fail!");
        }
        nodes = new ArrayList<>();
        for (int g = 1; g <= this.group; g++){
            int unit = size/group;
            List<Integer> node = new ArrayList<>();
            for (int i = (g-1)*unit+1+offset ; i <= g*unit+offset; i++){
                node.add(i);
            }
            nodes.add(node);
        }
    }
 
    /**
     * 开始计算 =======>>>
     *
     *          货架命中规则如下:
     *              安装位置:   [1]  [2]  |  [3]  [4]  --------  [5] [6]  |  [7] [8]
     *                  命中顺序:      1 -> 5 -> 4 -> 8 -> 2 -> 6 -> 3 -> 7 -> 1 ...
     *
     *          1.该规则适不限制货架数量,总数与组别在构造器中设置
     *          2.如有序列号起始问题,用偏移量规避即可
     *
     * @param curSeq 当前货架号
     * @return 规则命中货架号
     */
    public int start(int curSeq){
        Iterator<List<Integer>> iterator = nodes.iterator();
        while (iterator.hasNext()){
            List<Integer> node = iterator.next();
            if (node.contains(curSeq)) {
                int idx = node.indexOf(curSeq);
                // 是否为末尾货架
                if (iterator.hasNext()) {
                    return iterator.next().get(idx);
                } else {
                    List<Integer> first = nodes.get(0);
                    int val = first.get(idx);
                    int res = size / group + 1 + offset - val;
                    // 反向命中货架时不再是对立下标(相对于巷道)
                    if (res < val) {
                        // 轮询所有货架后重新开始定位
                        if (val - res - offset == 1) {
                            return first.get(0);
                        }
                        res = res + 1;
                    }
                    return res + offset;
                }
            }
        }
        return -1;
    }
 
    public Integer get(Integer curRow) {
        for (List<Integer> node : nodes){
            if (node.contains(curRow)) {
                return nodes.indexOf(node) + 1;
            }
        }
        throw new CoolException("货排检索系统报错, node:" + JSON.toJSONString(nodes) + ", curRow:" + curRow);
    }
 
    public static void main(String[] args) throws InterruptedException {
 
        double remainder = Arith.divides(1,16 - 1, 16);
        System.out.println(remainder);
        System.out.println((int) remainder);
//        Shelves shelves = new Shelves(8,2);
//        System.out.println(shelves.nodes.toString());
//        int start = 1;
//        while (true) {
//            System.out.println(start);
//            start = shelves.start(start);
//            Thread.sleep(500L);
//        }
    }
 
}