ImageVerifierCode 换一换
格式:DOCX , 页数:34 ,大小:211.61KB ,
资源ID:19906865      下载积分:12 金币
快捷下载
登录下载
邮箱/手机:
温馨提示:
快捷下载时,用户名和密码都是您填写的邮箱或者手机号,方便查询和重复下载(系统自动生成)。 如填写123,账号就是123,密码也是123。
特别说明:
请自助下载,系统不会自动发送文件的哦; 如果您已付费,想二次下载,请登录后访问:我的下载记录
支付方式: 支付宝    微信支付   
验证码:   换一换

加入VIP,免费下载
 

温馨提示:由于个人手机设置不同,如果发现不能下载,请复制以下地址【https://www.bdocx.com/down/19906865.html】到电脑端继续下载(重复下载不扣费)。

已注册用户请登录:
账号:
密码:
验证码:   换一换
  忘记密码?
三方登录: 微信登录   QQ登录  

下载须知

1: 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。
2: 试题试卷类文档,如果标题没有明确说明有答案则都视为没有答案,请知晓。
3: 文件的所有权益归上传用户所有。
4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
5. 本站仅提供交流平台,并不能对任何下载内容负责。
6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

版权提示 | 免责声明

本文(实验二 银行家算法Word文档下载推荐.docx)为本站会员(b****5)主动上传,冰豆网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。 若此文所含内容侵犯了您的版权或隐私,请立即通知冰豆网(发送邮件至service@bdocx.com或直接QQ联系客服),我们立即给予删除!

实验二 银行家算法Word文档下载推荐.docx

1、它表示系统是否有足够的资源分配给进程,使之运行完成,开始Finish(I)=false;当有足够资源分配给进程Pi时,令Finish(i)=true;2 从进程集合中找到一个能满足下述条件的进程。Finish(i)= = false;Need i work;如找到则执行步骤3;否则,执行步骤4;3 当进程Pi获得资源后,可顺利执行直到完成,并释放出分配给它的资源,故应执行Work = work + Allocation i Finish(i)=true;转向步骤2;4 若所有进程的Finish(i)都为true,则表示系统处于安全状态;否则,系统处于不安全状态。六、流程图七、源程序代码1银行家

2、算法类package BankerAlgorithm;public class Banker private int Available;/可利用资源向量 private int AllSource;/总资源数 private int Max;/最大需求矩阵 private int Allocation;/已分配资源矩阵 private int Need;/需求矩阵 private int Work;/工作向量 private int Request;/资源请求向量 private int Temp;/交换向量/ private boolean Finish;/判断进程是否可以得到资源 pri

3、vate int processCount;/进程数 private int sourceCount;/资源数 private String safeList = new String(); private int count; private String dataStrings; private int flag; public void initBanker(int processCount,int sourceCount) this.processCount = processCount; this.sourceCount = sourceCount; this.Max = new i

4、ntprocessCountsourceCount; this.Allocation = new intprocessCountsourceCount; this.Need = new intprocessCountsourceCount; this.Work = new intsourceCount; this.Request = new intsourceCount;/ this.Finish = new booleanprocessCount; this.dataStrings = new StringprocessCount6; this.Temp = new intprocessCo

5、unt; for (int i = 0; i processCount; i+) for (int j = 0; j AllSourcei) return false; return true; public boolean isMaxAllocation(int max,int allocation) /检查已分配资源数是否小于最大资源数 if ( allocationi maxi) public boolean isEnoughNeed(int row) /工作向量是否满足需求矩阵 if (Needrowi Worki) this.flag = 0; this.flag = 1; publ

6、ic boolean isEnoughReq(int row) /请求矩阵是否满足需求矩阵 if (Needrowi Availablei) public boolean isAvailable(int available) if (availablei 0) public boolean checkNeed(int need) /检查需求矩阵中资源是否都为0 if (needi!=0) public boolean isSafe() /检查是否安全 int i; for( i=0; iprocessCount ;i+) if(isEnoughNeed(Tempi-1) CountWork(T

7、empi-1); continue; else break; if(i=processCount) return true; else return false; public void CountWork(int row) /计算工作向量 Worki = Worki + Allocationrowi; public void getSafeList(int k, int n) /递归求安全序列 int m,a; if( k = n ) for(int j=0;jsourceCount;j+) Workj = Availablej; if(isSafe() for(a=0 ; a; safeL

8、ist += Tempa+n count+; for(int j=0; j j+) Workj = Availablej; else for(int i=k;i=n;i+) /排列 m=Tempk; Tempk=Tempi; Tempi=m; getSafeList(k+1, n); public void changeDataString() /设置数据 String s_available=new String(); String s_allocation = new String(); String s_need = new String(); String s_max = new St

9、ring(); s_available += this.Availablej + s_allocation += this.Allocationij + s_need += this.Needij + s_max += this.Maxij + this.dataStringsi1 = i+1+ this.dataStringsi2 = s_max; this.dataStringsi3 = s_allocation; this.dataStringsi4 = s_need; this.dataStrings05 = s_available; public void allocateSourc

10、e(int row) if (checkNeed(Needi) for (int j = 0; this.Availablej += this.Allocationij; this.Allocationij = 0; this.Maxij = 0; for(int i = 0; this.Availablei = this.Availablei-this.Requesti; this.Allocationrow-1i = this.Allocationrow-1i+this.Requesti; this.Needrow-1i = this.Needrow-1i-this.Requesti; c

11、hangeDataString(); public boolean requestSource(int row) count = 0; if (isEnoughReq(row-1) & isEnoughAva(row-1) allocateSource(row); return true; return false; public int getAvailable() return Available; public void setAvailable(int available) Available = available; public String getSafeList() retur

12、n safeList; public void setSafeList(String safeList) this.safeList = safeList; public int getCount() return count; public void setCount(int count) this.count = count; public String getDataStrings() return dataStrings; public void setDataStrings(String dataStrings) this.dataStrings = dataStrings; pub

13、lic int getFlag() return flag; public void setFlag(int flag) this.flag = flag;2界面类import org.eclipse.swt.widgets.Display;import org.eclipse.swt.widgets.Shell;import org.eclipse.swt.SWT;import org.eclipse.swt.widgets.Label;import org.eclipse.swt.widgets.MessageBox;import org.eclipse.swt.widgets.Table

14、Item;import org.eclipse.swt.widgets.Text;import org.eclipse.swt.widgets.Button;import org.eclipse.swt.widgets.Table;import org.eclipse.swt.widgets.TableColumn;import org.eclipse.swt.events.SelectionAdapter;import org.eclipse.swt.events.SelectionEvent;import org.eclipse.swt.custom.ScrolledComposite;i

15、mport org.eclipse.wb.swt.SWTResourceManager;public class BankerSWT protected Shell shell; private Text sourceCountText; private Text proCountText; private Text countText; private Text sourceTexts = new Text10; private Text maxTexts = new Text10; private Text allocationTexts = new Text10; private Tex

16、t requestTexts = new Text10; private Button button; private Label label_2; private Button button_1; private Label label_3; private Label label_4; private Button button_2; private Label lblNewLabel; private Table table; private Text requsetText; private Text securityText; private int row; private Ban

17、ker banker = new Banker(); /* * Launch the application. * param args */ public static void main(String args) try BankerSWT window = new BankerSWT(); window.open(); catch (Exception e) e.printStackTrace(); * Open the window. public void open() Display display = Display.getDefault(); createContents();

18、 shell.open(); shell.layout(); while (!shell.isDisposed() if (!display.readAndDispatch() display.sleep(); * Create contents of the window. protected void createContents() shell = new Shell(); shell.setSize(550, 475); shell.setText(银行家算法); Label label = new Label(shell, SWT.NONE); label.setBounds(10, 10, 84, 17); label.setText(u8BF7u8F93u5165u8D44u6E90u6570uFF1A sourceCountText = new Text(shell, SWT.BORDER); sourceCountText.setBounds(100, 10,

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1