验证排班的实例

 @Test
    public void sortClass() {
        //给10.1-10.9排班
        String[] date = {"2019-10-01",
                "2019-10-02",
                "2019-10-03",
                "2019-10-04",
                "2019-10-05",
                "2019-10-06",
                "2019-10-07",
                "2019-10-08",
                "2019-10-09"};

        String[] classS={
                "白班","黑班","蓝班","红班","绿班"
        };

        //班种备选人轮询的计数器
        TreeMap<String,Integer> numTree=new TreeMap<>();
        //默认班种中的备选人指针为0
        for(int k=0;k<classS.length;k++){
            numTree.put(classS[k],0);
        }

        //假定
        // 10.1到10.7号的班种为 白班,黑班,蓝班
        // 10.8是白班、红班、
        // 10月9号是黑班、绿班
        Map<String,TreeSet<String>> classOduty=new TreeMap<>();
        init(classOduty);

        //假定
        //白班的备选人是[白大-白五]
        //黑班的备选人是[黑大-黑三]
        //蓝班的备选人是[蓝大-蓝四]
        //红班的备选人是[红大-红七]
        //绿班的备选人是[绿大-绿三]
        TreeMap<String,String[]> dutyClass=new TreeMap<>();
        init(dutyClass);


        for (int i = 0; i < date.length; i++) {
            //10月1日-10月9日的处理
            paiban(date[i], numTree, classOduty, dutyClass);
        }

        //继续排 10月9日-10月31的班
        init_ext(classOduty);

        String[] date_ext = {
                "2019-10-10",
                "2019-10-11",
                "2019-10-12",
                "2019-10-13",
                "2019-10-14",
                "2019-10-15",
                "2019-10-16",
                "2019-10-17",
                "2019-10-18",
                "2019-10-19",
                "2019-10-20",
                "2019-10-21",
                "2019-10-22",
                "2019-10-23",
                "2019-10-24",
                "2019-10-25",
                "2019-10-26",
                "2019-10-27",
                "2019-10-28",
                "2019-10-29",
                "2019-10-30",
                "2019-10-31"};

        for (int m= 0; m < date_ext.length; m++) {
            //10月10日-10月19日的处理
            paiban(date_ext[m], numTree, classOduty, dutyClass);
        }
    }

    private void init_ext(Map<String, TreeSet<String>> classOduty) {
        TreeSet<String> temp4=new TreeSet<>();
        temp4.add("白班");
        temp4.add("黑班");
        temp4.add("蓝班");
        classOduty.put("2019-10-10",temp4);
        classOduty.put("2019-10-11",temp4);
        classOduty.put("2019-10-12",temp4);
        classOduty.put("2019-10-13",temp4);
        classOduty.put("2019-10-14",temp4);
        classOduty.put("2019-10-15",temp4);
        classOduty.put("2019-10-16",temp4);
        classOduty.put("2019-10-17",temp4);
        classOduty.put("2019-10-18",temp4);
        classOduty.put("2019-10-19",temp4);
        classOduty.put("2019-10-20",temp4);
        classOduty.put("2019-10-21",temp4);
        classOduty.put("2019-10-22",temp4);
        classOduty.put("2019-10-23",temp4);
        classOduty.put("2019-10-24",temp4);
        classOduty.put("2019-10-25",temp4);
        classOduty.put("2019-10-26",temp4);
        classOduty.put("2019-10-27",temp4);
        classOduty.put("2019-10-28",temp4);
        classOduty.put("2019-10-29",temp4);
        classOduty.put("2019-10-30",temp4);
        classOduty.put("2019-10-31",temp4);

    }

    private void init(TreeMap<String, String[]> dutyClass) {
        String whiteDuty[]={"白大","白二","白三","白四","白五"};
        String blackDuty[]={"黑大","黑二","黑三"};
        String blueDuty[]={"蓝大","蓝二","蓝三","蓝四"};
        String redDuty[]={"红大","红二","红二","红二","红二","红二","红二"};
        String greenDuty[]={"绿大","绿二","绿三"};

        dutyClass.put("白班",whiteDuty);
        dutyClass.put("黑班",blackDuty);
        dutyClass.put("蓝班",blueDuty);
        dutyClass.put("红班",redDuty);
        dutyClass.put("绿班",greenDuty);
    }

    private void init(Map<String, TreeSet<String>> classOduty) {
        TreeSet<String> temp=new TreeSet<>();
        temp.add("白班");
        temp.add("黑班");
        temp.add("蓝班");
        classOduty.put("2019-10-01",temp);
        classOduty.put("2019-10-02",temp);
        classOduty.put("2019-10-03",temp);
        classOduty.put("2019-10-04",temp);
        classOduty.put("2019-10-05",temp);
        classOduty.put("2019-10-06",temp);
        classOduty.put("2019-10-07",temp);
        TreeSet<String> temp1=new TreeSet<>();
        temp1.add("白班");
        temp1.add("红班");
        classOduty.put("2019-10-08",temp1);
        TreeSet<String> temp2=new TreeSet<>();
        temp2.add("黑班");
        temp2.add("绿班");
        temp2.add("蓝班");
        classOduty.put("2019-10-09",temp2);
    }

    private void paiban(String dateStr1, TreeMap<String, Integer> numTree, Map<String, TreeSet<String>> classOduty, TreeMap<String, String[]> dutyClass) {
        final String dateStr= dateStr1;
        TreeSet<String> sub=classOduty.get(dateStr);
        System.out.print(dateStr+"的排种:");
        sub.stream().forEach(cla->{
            //给班种排序、同时增加计数
            Integer index=numTree.get(cla);
            Integer temLength=dutyClass.get(cla).length;
            System.out.print(cla+"  : " +dutyClass.get(cla)[index]+"   ");
            index=(++index)%temLength;
            numTree.put(cla,index);
        });
        System.out.println();
    }

大学毕业前的排课系统,这周巧合之下,解决了,没有想象中那么难,关键在于因缘启示。

如果用于排课系统,应该是分步走:
比如排课天数,班级、教室,课程,老师。

首先得确认每周/月/年 有多少个课时。


先排好 天数 和 教室的对应。其次选 课程,再次选教师。

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

大巨魔战将

如果对您有帮助,请打赏1分钱

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值