コード例 #1
0
    private void CreateIndividual1(ref ch cc)
    {
        //对空染色体cc进行初始化为一个可行解
        //对每个空位塞课程,同时消除冲突
        for (int i = 1; i <= N; i++)                                  //班级
        {
            for (int j = 0; j < courseList.Length; j++)               //库里的课程数据
            {
                for (int t = 1; t <= courseList[j].Hour1; t++)        //按课时数量塞
                {
                    int k = GetRandnum.Next(1, M + 1);                //随机塞的位置为i,k
                    while (!cc.teacher[i, k].id.Equals("nullstring")) //不为空就继续随机,直到随机到一个空位
                    {
                        k = GetRandnum.Next(1, M + 1);
                    }
                    cc.teacher[i, k].id  = teacherArrange[i - 1, j].No; //塞进表
                    cc.teacher[i, k].cno = teacherArrange[i - 1, j].Courseno;
                    RemoveConflict(ref cc, i, k);                       //同时消除冲突
                }
            }
        }

        for (int t = 1; t <= N; t++)
        {
            fresh_fitstu(ref cc, t);//init()更新fit值,每次班级课表变动也要更新
        }
    }
コード例 #2
0
    //挑选
    private void Select()
    {
        Roulette();//.r

        //选择了X个个体
        ch[] delta = new ch[X + 1];

        int k = 1;

        //从S个个体中选择
        for (int i = 1; i <= S; i++)
        {
            //将c[i].r个i个体选择出来
            for (int j = 1; j <= c[i].r; j++)
            {
                delta[k] = c[i];//选择过程
                k++;
            }
        }

        //选择出来后为X个个体
        for (int t = 1; t <= X; t++)
        {
            c[t] = delta[t];
        }
    }
コード例 #3
0
    private void init()
    {
        //N,M初始化
        N = teacherArrange.GetLength(0);
        M = 0;
        for (int t = 0; t < courseList.Length; t++)
        {
            M += courseList[t].Hour1;
            course_week_sum.Add(teacherArrange[0, t].Courseno, courseList[t].Hour1);
        }

        //规模为基因数目2倍
        S = N * 2;
        //选择操作之后种群的个数
        X = ((int)((double)S * Pc)) / 2 * 2;//保证为正偶数

        //染色体种群初始化
        c = new ch[S + 2];//用到c[S+1]
        for (int t = 1; t <= S; t++)
        {
            c[t].teacher = new Tea[N + 1, M + 1];
            for (int i = 1; i <= N; i++)
            {
                for (int j = 1; j <= M; j++)
                {
                    c[t].teacher[i, j]     = new Tea();
                    c[t].teacher[i, j].id  = "nullstring";
                    c[t].teacher[i, j].cno = "nullstring";
                }
            }
            c[t].fitstu = new int[N + 1];
        }
        ans.teacher = new Tea[N + 1, M + 1];
        ans.fit     = -1;                     //设置一个小值

        course_week_sum.Add("nullstring", 0); //防止后面调用产生空指针

        for (int t = 1; t <= S; t++)
        {
            CreateIndividual(ref c[t]);
        }

        fitsum = 0;
        for (int t = 1; t <= S; t++)
        {
            if (ans.fit < c[t].fit)
            {
                ans = c[t];
            }
            fitsum += c[t].fit;
        }

        for (int t = 1; t <= S; t++)
        {
            c[t].d = (double)c[t].fit / (double)fitsum;
        }
    }
コード例 #4
0
 public void reveal(ch.cyberduck.core.local.Local l)
 {
     if (l.exists())
     {
         //select first file downloaded. We could just open the containing folder alternatively.
         ApplicationLauncherFactory.get().open(new Application("explorer.exe", null),
                                               "/select, " + l.getAbsolute());
     }
 }
コード例 #5
0
    private void RemoveConflict1(ref ch cc, int i, int j)
    {
        //没有冲突解决个毛线
        if (Conflict(ref cc, i, j, cc.teacher[i, j].id) == 0 || i == 0)
        {
            return;
        }

        int t = GetRandnum.Next(1, M + 1);

        int conj = 0, cont = 0;//与 i行j,t列 发生冲突的行数
        int loop    = 0;
        int maxloop = M;

        while (loop++ < maxloop)//防止死循环
        {
            //防止自己和自己调换
            while (t == j)
            {
                t = GetRandnum.Next(1, M + 1);
            }

            //与 i行j,t列 发生冲突的行数
            conj = Conflict(ref cc, i, j, cc.teacher[i, t].id);
            cont = Conflict(ref cc, i, t, cc.teacher[i, j].id);

            //有冲突继续随机选择//希望找到一个位置交换课程而消除冲突
            if (conj > 0 || cont > 0)
            {
                continue;                      //尽量避免调换之后还有冲突
            }
            else
            {
                break;
            }
        }

        Swap <Tea>(ref cc.teacher[i, j], ref cc.teacher[i, t]);

        //有可能还有冲突//递归消除冲突
        //改动其他行
        //if (conj > 0) { RemoveConflict(ref cc, conj, j); }
        //if (cont > 0) { RemoveConflict(ref cc, cont, t); }

        //不改动其他行
        if (conj > 0)
        {
            RemoveConflict(ref cc, i, j);
        }
        if (cont > 0)
        {
            RemoveConflict(ref cc, i, t);
        }
    }
コード例 #6
0
    //整个课表的学生fit值
    private int fit_stu(ref ch cc)
    {
        int sum = 0;

        //N个班级之和
        for (int t = 1; t < N; t++)
        {
            sum += cc.fitstu[t];//.fitstu[]从init()初始化后从头到尾凡有变动即更新
        }
        return(sum);
    }
コード例 #7
0
    //计算一个课表的总fit值
    private int count_fit(ref ch cc)
    {
        // 课表总fit值为 每个班级fit_stu + 每个老师fit_tch
        int fitvaluesum = fit_stu(ref cc) + fit_tch(ref cc);

        //让个体适应度大于0
        if (fitvaluesum < 0)
        {
            fitvaluesum = 0;
        }
        return(cc.fit = fitvaluesum);
    }
コード例 #8
0
 //返回某个冲突的行数//0代表无冲突
 private int Conflict(ref ch cc, int i, int j, string str)
 {
     if (str.Equals("nullstring"))
     {
         return(0);                         //空字符串代表初始化时候未放入
     }
     for (int t = 1; t <= N; t++)
     {
         if (t == i)
         {
             continue;
         }
         if (cc.teacher[t, j].id == str)
         {
             return(t);//true
         }
     }
     return(0);//false
 }
コード例 #9
0
 //更新下一代基本成员值
 private void Estimate()
 {
     //当前一代的所有个体fit值之和
     fitsum = 0;
     for (int t = 1; t <= S; t++)
     {
         //更新每个个体解的fit值
         c[t].fit = count_fit(ref c[t]);
         //更新当前最佳解
         if (ans.fit < c[t].fit)
         {
             ans = c[t];
         }
         //总fit值
         fitsum += c[t].fit;
     }
     //更新其他辅助值
     for (int t = 1; t <= N; t++)
     {
         c[t].d = (double)c[t].fit / (double)fitsum;
         c[t].r = 0;
     }
 }
コード例 #10
0
 public void bounce(ch.cyberduck.core.local.Local local)
 {
     ;
 }
コード例 #11
0
    //整个课表老师的fit值
    private int fit_tch(ref ch cc)
    {
        int fitvalue = 100;
        Dictionary <string, int> max_map = new Dictionary <string, int>();

        max_map.Clear();
        Dictionary <string, int> min_map = new Dictionary <string, int>();

        min_map.Clear();

        Dictionary <string, int> t_map = new Dictionary <string, int>();

        for (int t = 1; t <= 5; t++)//星期t
        {
            t_map.Clear();
            for (int i = 1; i <= N; i++)         //i班
            {
                for (int j = 1; j <= M / 5; j++) //第j节课
                {
                    if (t_map.ContainsKey(cc.teacher[i, (t - 1) * M / 5 + j].id))
                    {
                        t_map[cc.teacher[i, (t - 1) * M / 5 + j].id]++;
                    }
                    else
                    {
                        t_map.Add(cc.teacher[i, (t - 1) * M / 5 + j].id, 1);
                    }
                }
            }


            //更新min_map&&max_map
            foreach (var item in t_map)
            {
                if (min_map.ContainsKey(item.Key))
                {
                    min_map[item.Key] = min_map[item.Key] < item.Value ? min_map[item.Key] : item.Value;
                    max_map[item.Key] = max_map[item.Key] > item.Value ? max_map[item.Key] : item.Value;
                }
                else
                {
                    min_map.Add(item.Key, item.Value);
                    max_map.Add(item.Key, item.Value);
                }

                ////////////////扣分明细///////////////
                //老师一天上课不超过4节
                if (item.Value > 4)//老师一天超过4节课
                {
                    //fitvalue -= item.Value;
                }
            }
        }

        foreach (var item in max_map)
        {
            if (item.Value - min_map[item.Key] > 1)
            {
                fitvalue -= (item.Value - min_map[item.Key]);
            }
        }

        return(fitvalue);
    }
コード例 #12
0
 public override ch.cyberduck.core.sftp.HostKeyController create(ch.cyberduck.ui.Controller c)
 {
     return new HostKeyController(c as WindowController);
 }
コード例 #13
0
 var(ch, st) = state;
コード例 #14
0
ファイル: LoginController.cs プロジェクト: kaduardo/cyberduck
 protected override ch.cyberduck.core.LoginController create(ch.cyberduck.ui.Controller c)
 {
     return new LoginController((WindowController) c);
 }
コード例 #15
0
ファイル: LocalImpl.cs プロジェクト: kaduardo/cyberduck
 protected override ch.cyberduck.core.local.Local create(ch.cyberduck.core.local.Local parent, string name)
 {
     return new LocalImpl(parent, name);
 }
コード例 #16
0
ファイル: LocalImpl.cs プロジェクト: kaduardo/cyberduck
 public LocalImpl(ch.cyberduck.core.local.Local parent, string name)
     : base(parent, name)
 {
     ;
 }
コード例 #17
0
            /// <summary>
            /// Universal, but a bit slower (because of the yield returns) than those ones with IDictionary or IList
            /// </summary>
            /// <param name="isNullChecked"></param>
            /// <returns></returns>
            public IEnumerable <Decoder> GetCollection(bool isNullChecked = false)
            {
                ulong prot = 0;

                if (!isNullChecked)
                {
                    if (!this.GetDigit(out prot))
                    {
                        prot = 1;
                    }

                    //prot = this.GetDigit();
                }

                if (prot == 0)
                {
                    if (this.GetDigit(out prot))
                    {
                        int collectionLength = (int)prot;
                        //int collectionLength = (int)this.GetDigit();

                        if (collectionLength > 0) //JS not noted change
                        {
                            coldeepcnt++;

                            int cp = this.encPos;

                            ch cdi = null;
                            if (coldeep.Count < coldeepcnt)
                            {
                                cdi = new ch();
                                coldeep.Add(cdi);
                            }
                            else
                            {
                                cdi = coldeep[coldeepcnt - 1];
                            }

                            if (this.qb > 1)
                            {
                                cdi.collectionShiftToPass = 0;
                                cdi.collectionShift       = this.qb - 1;
                                this.encPos          = cp + collectionLength - cdi.collectionShift; //JS not noted change
                                cdi.collectionBuffer = Read(cdi.collectionShift);
                                this.encPos          = cp;
                            }
                            else
                            {
                                cdi.collectionShift       = 0;
                                cdi.collectionShiftToPass = 0;
                            }


                            cdi.collectionIsFinished = false;

                            while (!cdi.collectionIsFinished)
                            {
                                yield return(this);

                                if ((this.encPos - (cp - cdi.collectionShift)) == collectionLength)
                                {
                                    cdi.collectionIsFinished = true;
                                    if (cdi.collectionShift > 0)
                                    {
                                        this.encPos += cdi.collectionShift;
                                    }

                                    coldeepcnt--;
                                    break;
                                }
                            }
                        }
                    }
                }
            } //eof
コード例 #18
0
            void GetCollection <K, V>(Func <K> fk, Func <V> fv, IDictionary <K, V> dict, IList <K> lst, ISet <K> set, bool isNullChecked = false)
            {
                ulong prot = 0;

                if (!isNullChecked)
                {
                    if (!this.GetDigit(out prot))
                    {
                        prot = 1;
                    }

                    //prot = this.GetDigit();
                }

                if (prot == 0)
                {
                    if (this.GetDigit(out prot))
                    {
                        int collectionLength = (int)prot;
                        //int collectionLength = (int)this.GetDigit();

                        if (collectionLength == 0) //JS not noted change
                        {
                            return;
                        }

                        coldeepcnt++;

                        int cp = this.encPos;

                        ch cdi = null;
                        if (coldeep.Count < coldeepcnt)
                        {
                            cdi = new ch();
                            coldeep.Add(cdi);
                        }
                        else
                        {
                            cdi = coldeep[coldeepcnt - 1];
                        }

                        if (this.qb > 1)
                        {
                            cdi.collectionShiftToPass = 0;
                            cdi.collectionShift       = this.qb - 1;
                            this.encPos          = cp + collectionLength - cdi.collectionShift; //JS not noted change
                            cdi.collectionBuffer = Read(cdi.collectionShift);
                            this.encPos          = cp;
                            //collectionPos += collectionShift;
                        }
                        else
                        {
                            cdi.collectionShift       = 0;
                            cdi.collectionShiftToPass = 0;
                        }


                        cdi.collectionIsFinished = false;

                        while (true)
                        {
                            if (dict == null)
                            {
                                if (lst == null)
                                {
                                    set.Add(fk());
                                }
                                else
                                {
                                    lst.Add(fk());
                                }
                            }
                            else
                            {
                                dict.Add(fk(), fv());
                            }


                            if ((this.encPos - (cp - cdi.collectionShift)) == collectionLength)
                            {
                                cdi.collectionIsFinished = true;
                                if (cdi.collectionShift > 0)
                                {
                                    this.encPos += cdi.collectionShift;
                                }

                                coldeepcnt--;

                                break;
                            }
                        }
                    }
                }
            } //eof
コード例 #19
0
    //t班的学生fit值更新//init()以及班级课表变动的时候触发
    private void fresh_fitstu(ref ch cc, int t)
    {
        int fitvalue = 100;//BESTFITNESS
        Dictionary <string, int> max_map = new Dictionary <string, int>();

        max_map.Clear();
        Dictionary <string, int> min_map = new Dictionary <string, int>();

        min_map.Clear();

        string yuwencno = teacherArrange[0, 0].Courseno;

        for (int i = 1; i <= 5; i++)//每个星期5天课程确定
        {
            //对于每天课程进行评判
            Dictionary <string, int> c_map = new Dictionary <string, int>();
            c_map.Clear();

            //c_map更新//t班星期i的老师工号对应课时数
            for (int j = 1; j <= M / 5; j++)
            {
                if (cc.teacher[t, (i - 1) * M / 5 + j].cno.Equals(yuwencno))
                {
                    ////////////////扣分明细///////////////
                    //语文课尽量靠前
                    fitvalue -= (j - 1) * 3;
                }
                if (c_map.ContainsKey(cc.teacher[t, (i - 1) * M / 5 + j].id))
                {
                    c_map[cc.teacher[t, (i - 1) * M / 5 + j].id]++;
                }
                else
                {
                    c_map.Add(cc.teacher[t, (i - 1) * M / 5 + j].id, 1);
                }
            }

            //判断每天课时评分
            foreach (var item in c_map)
            {
                //学生同一天同一门课程
                if (item.Value <= 1)
                {
                    continue;
                }
                else if (item.Value == 2)
                {
                    //第一次和第二次上课时间
                    int early = 0, late = 0;
                    for (int j = 1; j <= M / 5; j++)
                    {
                        if (item.Equals(cc.teacher[t, (i - 1) * M / 5 + j].id))
                        {
                            if (early == 0)
                            {
                                early = j;
                            }
                            else
                            {
                                late = j;
                                break;
                            }
                        }
                    }

                    ////////////////扣分明细///////////////
                    //学生一天两节的同一门课间距最小//或分上下午
                    if ((early > 4 && late > 4) || (early < 5 && late < 5))
                    {
                        if (late - early - 1 == 0)
                        {
                            //相邻可以接受
                        }
                        else
                        {
                            //同上午同下午不相邻扣分
                            fitvalue -= (late - early) * 10;
                        }
                    }
                    else
                    {
                        ;//可以接受上下午两节
                    }
                }
                else//>=3
                {
                    ////////////////扣分明细///////////////
                    //学生一天同一门课程不得超过2节
                    fitvalue -= item.Value * 10;//item.Value课程的课时数
                }
            }

            //更新min_map&&max_map
            foreach (var item in c_map)
            {
                if (min_map.ContainsKey(item.Key))
                {
                    min_map[item.Key] = min_map[item.Key] < item.Value ? min_map[item.Key] : item.Value;
                    max_map[item.Key] = max_map[item.Key] > item.Value ? max_map[item.Key] : item.Value;
                }
                else
                {
                    min_map.Add(item.Key, item.Value);
                    max_map.Add(item.Key, item.Value);
                }
            }
        }

        foreach (var item in max_map)
        {
            if (item.Value - min_map[item.Key] > 1)
            {
                ////////////////扣分明细///////////////
                //学生一周的用一门课时数的极差应不大于1//例如语文5天课时数分别为12111
                fitvalue -= (item.Value - min_map[item.Key]);
            }
        }

        if (fitvalue < 0)
        {
            fitvalue = 0;        //非负数
        }
        cc.fitstu[t] = fitvalue; //每个班的fit_stu
    }
コード例 #20
0
 //在可行解(某染色体)cc中,t,i与t,j交换无冲突
 private bool SwapConflict(ref ch cc, int t, int i, int j)
 {
     return(Conflict(ref cc, t, i, cc.teacher[t, j].id) > 0 || Conflict(ref cc, t, j, cc.teacher[t, i].id) > 0);
 }
コード例 #21
0
 public bool open(ch.cyberduck.core.local.Local local)
 {
     return Utils.StartProcess(local.getAbsolute());
 }
コード例 #22
0
    private void RemoveConflict(ref ch cc, int i, int j)
    {
        //没有冲突解决个毛线
        if (Conflict(ref cc, i, j, cc.teacher[i, j].id) == 0 || i == 0)
        {
            return;
        }

        int pos = 0;//待交换的地方

        //课时大于等于5//语数外
        if (course_week_sum[cc.teacher[i, j].cno] >= 5)
        {
            int day, tim;//星期几//节次//
            day = (j - 1) / 8 + 1;
            tim = (j - 1) % 8 + 1;
            //j = (day-1)*8+tim

            int count = 0;
            for (int t = 1; t <= 8; t++)
            {
                if (cc.teacher[i, (day - 1) * 8 + t].id == cc.teacher[i, j].id)
                {
                    count++;
                }
            }

            //以下均不考虑死循环

            //这一天只有一节课
            if (count == 1)
            {
                //和当天课程交换
                pos = (day - 1) * 8 + GetRandnum.Next(1, 9);//1 ~ 8
                while (pos % 8 == tim || SwapConflict(ref cc, i, pos, j))
                {
                    pos = (day - 1) * 8 + GetRandnum.Next(1, 9);
                }
            }
            else//两节课以上
            {
                //和任意非5周课时以上课程交换
                pos = GetRandnum.Next(1, M + 1);//1 ~ M

                //if ((pos - 1) / 8 + 1 == day) //和当天交换
                {
                    pos = (day - 1) * 8 + GetRandnum.Next(1, 9);//1 ~ 8
                    while (pos % 8 == tim || SwapConflict(ref cc, i, pos, j))
                    {
                        pos = (day - 1) * 8 + GetRandnum.Next(1, 9);
                    }
                }

                /*else//其他天
                 * {
                 *  pos = GetRandnum.Next(1, M + 1);
                 *  while (course_week_sum[cc.teacher[i, pos].cno] >= 5 || (pos - 1) / 8 + 1 == day || Conflict(ref cc, i, pos, cc.teacher[i, j].id) > 0 || Conflict(ref cc, i, j, cc.teacher[i, pos].id) > 0)
                 *  {
                 *      pos = GetRandnum.Next(1, M + 1);
                 *  }
                 * }*/
            }
        }
        else//课时数小于5//美术音乐之类
        {
            pos = GetRandnum.Next(1, M + 1);//1 ~ M
            while (course_week_sum[cc.teacher[i, pos].cno] >= 5 || pos == j || SwapConflict(ref cc, i, pos, j))
            {
                pos = GetRandnum.Next(1, M + 1);
            }
        }

        Swap <Tea>(ref cc.teacher[i, j], ref cc.teacher[i, pos]);
    }
コード例 #23
0
    private void CreateIndividual(ref ch cc)
    {
        //对空染色体cc进行初始化为一个可行解
        //对每个空位塞课程,同时消除冲突
        for (int i = 1; i <= N; i++)                    //班级
        {
            for (int j = 0; j < courseList.Length; j++) //库里的课程数据
            {
                //语数外
                if (courseList[j].Hour1 >= 5)
                {
                    //先5,10,15课时分别安排不同5天
                    for (int count = courseList[j].Hour1 / 5; count >= 1; count--)
                    {
                        for (int t = 1; t <= 5; t++)
                        {
                            int pos = (t - 1) * 8 + GetRandnum.Next(1, 9);//pos刚好在星期t
                            while (!cc.teacher[i, pos].id.Equals("nullstring"))
                            {
                                pos = (t - 1) * 8 + GetRandnum.Next(1, 9);//pos刚好在星期t
                            }
                            //塞到这一天的空位然后消除冲突
                            cc.teacher[i, pos].id  = teacherArrange[i - 1, j].No;
                            cc.teacher[i, pos].cno = teacherArrange[i - 1, j].Courseno;
                            //然后消除矛盾
                            RemoveConflict(ref cc, i, pos);
                        }
                    }

                    //剩下课时不同天
                    Random_Permutation RP = new Random_Permutation(5);
                    int[] randpermutation = RP.NextRandom();

                    for (int t = 0; t < courseList[j].Hour1 % 5; t++)
                    {
                        int pos = 8 * (randpermutation[t]) + GetRandnum.Next(1, 9);
                        while (!cc.teacher[i, pos].id.Equals("nullstring"))
                        {
                            pos = 8 * (randpermutation[t]) + GetRandnum.Next(1, 9);
                        }
                        //塞到这一天的空位然后消除冲突
                        cc.teacher[i, pos].id  = teacherArrange[i - 1, j].No;
                        cc.teacher[i, pos].cno = teacherArrange[i - 1, j].Courseno;
                        //然后消除矛盾
                        RemoveConflict(ref cc, i, pos);
                    }
                }
                else//政史地
                {
                    for (int t = 1; t <= courseList[j].Hour1; t++)//按课时数量塞
                    {
                        int k = GetRandnum.Next(1, M + 1);                //随机塞的位置为i,k
                        while (!cc.teacher[i, k].id.Equals("nullstring")) //不为空就继续随机,直到随机到一个空位
                        {
                            k = GetRandnum.Next(1, M + 1);
                        }
                        cc.teacher[i, k].id  = teacherArrange[i - 1, j].No; //塞进表
                        cc.teacher[i, k].cno = teacherArrange[i - 1, j].Courseno;
                        RemoveConflict(ref cc, i, k);                       //同时消除冲突
                    }
                }
            }
        }

        for (int t = 1; t <= N; t++)
        {
            fresh_fitstu(ref cc, t);//init()更新fit值,每次班级课表变动也要更新
        }
    }
コード例 #24
0
 public bool open(ch.cyberduck.core.local.Local local, Application application)
 {
     return open(application, local.getAbsolute());
 }
コード例 #25
0
 public string Create(ch p)
 {
     return(_protocolsBL.Create(null));
 }