操作系统课设 移动臂模拟调度

操作系统课设 移动臂模拟调度


头文件
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QMainWindow>
#include <QTimer>

namespace Ui {
class MainWindow;
}

class MainWindow : public QMainWindow
{
    Q_OBJECT

public:
    explicit MainWindow(QWidget *parent = 0);
    ~MainWindow();

private slots:
    void change();

    void on_pushButton_clicked();

private:
    Ui::MainWindow *ui;
    QTimer timer;
    bool up;
    int flag;//1,2,3,4
    int a[10];
    int s[2];
    int scan_c[3];
    int lenth = 0;
    int localplace = 0;
    int floorlenth = 0;
    int scanlenth = 0;

    void fsfc();
    void sstf();

    void floor();
    void scan();
};

#endif // MAINWINDOW_H

mianwindow.cpp

#include "mainwindow.h"
#include "ui_mainwindow.h"

MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow),
    timer(this),
    up(true)
{
    ui->setupUi(this);
    timer.setSingleShot(false);
    timer.setInterval(40);
    connect(&timer,&QTimer::timeout,this,&MainWindow::change);
    timer.start();
}

MainWindow::~MainWindow()
{
    delete ui;
}

void MainWindow::change()
{
    if(localplace == 9){
        timer.stop();
        return;
    }
    if(floorlenth == 2){
        timer.stop();
        return;
    }
    if(scanlenth == 3){
        timer.stop();
        return;
    }
    if(flag == 1)
    {

        fsfc();
    }
    if(flag ==2)
    {
        sstf();
    }
    if(flag == 3)
    {
        floor();
    }
    if(flag == 4)
    {
        scan();
    }

}

void MainWindow::on_pushButton_clicked()
{
    a[0] = ui->lineEdit_input1->text().toInt();
    a[1] = ui->lineEdit_input2->text().toInt();
    a[2] = ui->lineEdit_input3->text().toInt();
    a[3] = ui->lineEdit_input4->text().toInt();
    a[4] = ui->lineEdit_input5->text().toInt();
    a[5] = ui->lineEdit_input6->text().toInt();
    a[6] = ui->lineEdit_input7->text().toInt();
    a[7] = ui->lineEdit_input8->text().toInt();
    a[8] = ui->lineEdit_input9->text().toInt();

    if(ui->radioButton_fcfs->isChecked()){
        lenth = -9;
        flag = 1;
    }
    if(ui->radioButton_mint->isChecked()){
        flag = 2;
    }
    if(ui->radioButton_lift->isChecked()){
        flag = 3;
    }
    if(ui->radioButton_scan->isChecked()){
        flag = 4;
    }

    ui->lineEdit_lenth->setText("");
    localplace = 0;

    timer.start();
}


void MainWindow::fsfc()
{

    int num = ui->verticalSlider->value();
    up ? (num += 1):(num -= 1);
    if(num >= 200)
    {
        up = false;
        lenth++;
    }
    if(num <= 0)
    {
        up = true;
        lenth++;
    }
    if(num > a[localplace])
    {

        up = false;
        lenth++;
    }
    if(num < a[localplace])
    {
        up = true;
        lenth++;
    }
    if(num == a[localplace])
        localplace++;

    ui->verticalSlider->setValue(num);

    ui->lineEdit_lenth->setText(QString::number(lenth));
}


void MainWindow::sstf()
{

}


void MainWindow::floor()
{
    int max = 0,min = 0;
    int num = ui->verticalSlider->value();
    for(int i = 0; i < 9; ++i)
    {

        if(max < a[i])
            max = a[i];
    }
    min = a[0];
    for(int i = 1; i < 9; ++i)
    {

        if(min > a[i])
            min = a[i];
    }
    s[0] = max;
    s[1] = min;
    up ? (num += 1):(num -= 1);

    if(num > s[floorlenth])
    {

        up = false;
        lenth++;
    }
    if(num < s[floorlenth])
    {
        up = true;
        lenth++;
    }
    if(num == s[floorlenth])
        floorlenth++;

    ui->verticalSlider->setValue(num);

    ui->lineEdit_lenth->setText(QString::number(lenth));
}


void MainWindow::scan()
{

    int stop_floor = 0;

    int num = ui->verticalSlider->value();
    for (int i = 0; i < 9; i++)
    {
        for (int j = i; j < 9; j++)
        {
            if (a[i] > a[j])
            {
                int temp = a[i];
                a[i] = a[j];
                a[j] = temp;
            }
        }
    }
    for(int i = 0; i < 9; i++)
    {
       if(stop_floor <= 125)
       {
            if(a[i] < 125)
            {
                if(125 - a[i] < (125 -stop_floor))
                    stop_floor =a[i];
            }
       }
       if(stop_floor > 125)
       {
            if(a[i] < 125)
            {
                if(125 - a[i] < (stop_floor - 125))
                    stop_floor =a[i];
            }
       }
    }
    scan_c[0] = a[8];
    scan_c[1] = a[0];
    scan_c[2] = stop_floor;
    up ? (num += 1):(num -= 1);

    if(num < 200)
    {
        up = true;

    }
    if(num == 200)
    {
        ui->verticalSlider->setValue(0);
        num = ui->verticalSlider->value();
        up = true;
        scanlenth++;
    }

    if(num == scan_c[scanlenth])
        scanlenth++;
    lenth++;
    ui->verticalSlider->setValue(num);

    ui->lineEdit_lenth->setText(QString::number(lenth));
}

main.cpp


#include "mainwindow.h"
#include <QApplication>

int main(int argc, char *argv[])
{
    QApplication a(argc, argv);
    MainWindow w;
    w.show();

    return a.exec();
}

最后的效果


我很满意!!!!!!!!

  • 2
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值