Заглавная страница Избранные статьи Случайная статья Познавательные статьи Новые добавления Обратная связь FAQ Написать работу КАТЕГОРИИ: ТОП 10 на сайте Приготовление дезинфицирующих растворов различной концентрацииТехника нижней прямой подачи мяча. Франко-прусская война (причины и последствия) Организация работы процедурного кабинета Смысловое и механическое запоминание, их место и роль в усвоении знаний Коммуникативные барьеры и пути их преодоления Обработка изделий медицинского назначения многократного применения Образцы текста публицистического стиля Четыре типа изменения баланса Задачи с ответами для Всероссийской олимпиады по праву
Мы поможем в написании ваших работ! ЗНАЕТЕ ЛИ ВЫ?
Влияние общества на человека
Приготовление дезинфицирующих растворов различной концентрации Практические работы по географии для 6 класса Организация работы процедурного кабинета Изменения в неживой природе осенью Уборка процедурного кабинета Сольфеджио. Все правила по сольфеджио Балочные системы. Определение реакций опор и моментов защемления |
Додаток А. Програмний код для обробки XML файлу з налаштуваннями програмиСодержание книги
Поиск на нашем сайте import javax.xml.parsers.DocumentBuilderFactory; import javax.xml.parsers.DocumentBuilder; import org.w3c.dom.Document; import org.w3c.dom.NodeList; import org.w3c.dom.Node; import org.w3c.dom.Element; import java.io.File; import org.math.array.util.*; import java.lang.Math.*; import org.math.array.DoubleArray.*; public class XMLInterface { private static double dt; private static int inputs, outputs, xsize; private static double[][] ad, bd, c, d, ar, br, cr; private static int[] uplimits, downlimits; private static double[] unom, ynom, fmax; private final String OBJECT_FILE="data/object.xml";
public static double getDt() {return dt;} public static int getInputs() {return inputs;} public static int getOutputs() {return outputs;} public static int getXsize() {return xsize;} public static int[] getUplimits() {return uplimits;} public static int[] getDownlimits() {return downlimits;} public static double[] getUnom() {return unom;} public static double[] getYnom() {return ynom;} public static double[] getFmax() {return fmax;} public static double[][] getAd() {return ad;} public static double[][] getBd() {return bd;} public static double[][] getC() {return c;} public static double[][] getD() {return d;} public static double[][] getAr() {return ar;} public static double[][] getBr() {return br;} public static double[][] getCr() {return cr;} /** *Метод для завантаження матриці в текстовому поданні до двовимірний масив Java (s–рядок, columnDelimiter – роздільник cтовпців, rowDelimiter – роздільник рядків) */ private static double[][] readStringDouble (String s, String columnDelimiter, String rowDelimiter) { double[][] array; String[]rows = s.split (rowDelimiter); array = new double [rows.length][]; for (int i=0; i<rows.length;i++) { String[]cols = rows[i].split (columnDelimiter); array[i]= new double[cols.length]; for (int j=0;j<cols.length;j++) { array[i][j]=Double.parseDouble(cols[j]); } } return array; } public XMLInterface() { try { File fXmlFile = new File (OBJECT_FILE); DocumentBuilderFactory dbFactory =DocumentBuilderFactory.newInstance(); DocumentBuilder dBuilder=dbFactory.newDocumentBuilder(); Document doc=dBuilder.parse (fXmlFile); doc.getDocumentElement ().normalize (); NodeList Nlc; Element Elements; String s; Nlc=doc.getElementsByTagName ("dt"); Elements = (Element) Nlc.item(0); s = Elements.getChildNodes ().item (0).getNodeValue ().trim (); this.dt=Double.valueOf (s); Nlc=doc.getElementsByTagName ("inputs"); Elements = (Element) Nlc.item(0); s = Elements.getChildNodes ().item (0).getNodeValue ().trim (); this.inputs=Integer.valueOf (s); Nlc=doc.getElementsByTagName ("outputs"); Elements = (Element) Nlc.item(0); s = Elements.getChildNodes ().item (0).getNodeValue ().trim (); this.outputs=Integer.valueOf (s); Nlc=doc.getElementsByTagName ("xsize"); Elements = (Element) Nlc.item(0); s = Elements.getChildNodes ().item (0).getNodeValue ().trim (); this.xsize=Integer.valueOf (s); Nlc=doc.getElementsByTagName ("ar"); Elements = (Element) Nlc.item(0); s = Elements.getChildNodes ().item (0).getNodeValue ().trim (); this.ar=readStringDouble (s, "\t", "\n"); Nlc=doc.getElementsByTagName ("br"); Elements = (Element) Nlc.item(0); s = Elements.getChildNodes ().item (0).getNodeValue ().trim (); this.br=readStringDouble (s, "\t", "\n"); Nlc=doc.getElementsByTagName ("cr"); Elements = (Element) Nlc.item(0); s = Elements.getChildNodes ().item (0).getNodeValue ().trim (); this.cr=readStringDouble (s, "\t", "\n"); Nlc=doc.getElementsByTagName ("ad"); Elements = (Element) Nlc.item(0); s = Elements.getChildNodes ().item (0).getNodeValue ().trim (); this.ad=readStringDouble (s, "\t", "\n"); Nlc=doc.getElementsByTagName ("bd"); Elements = (Element) Nlc.item(0); s = Elements.getChildNodes ().item (0).getNodeValue ().trim (); this.bd=readStringDouble (s, "\t", "\n"); Nlc=doc.getElementsByTagName ("c"); Elements = (Element) Nlc.item(0); s = Elements.getChildNodes ().item (0).getNodeValue ().trim (); this.c=readStringDouble (s, "\t", "\n"); Nlc=doc.getElementsByTagName ("d"); Elements = (Element) Nlc.item(0); s = Elements.getChildNodes ().item (0).getNodeValue ().trim (); this.d=readStringDouble (s, "\t", "\n"); this.uplimits = new int [this.outputs]; Nlc = doc.getElementsByTagName ("uplimits"); Elements = (Element) Nlc.item(0); s= Elements.getChildNodes ().item (0).getNodeValue().trim (); String [] ss; ss=s.split(","); for (int i=0;i<ss.length;i++) this.uplimits[i]=Integer.valueOf (ss[i].trim()); this.downlimits = new int [this.outputs]; Nlc = doc.getElementsByTagName ("downlimits"); Elements = (Element) Nlc.item(0); s= Elements.getChildNodes().item (0).getNodeValue().trim (); ss=s.split(","); for (int i=0;i<ss.length;i++) this.downlimits[i]=Integer.valueOf (ss[i].trim()); this.unom=new double[this.inputs]; this.ynom=new double[this.inputs]; this.fmax=new double[this.inputs]; this.unom = new double [this.outputs]; Nlc = doc.getElementsByTagName ("unom"); Elements = (Element) Nlc.item(0); s= Elements.getChildNodes().item (0).getNodeValue().trim (); ss=s.split(","); for (int i=0;i<ss.length;i++) this.unom[i]=Double.valueOf (ss[i].trim()); this.ynom = new double [this.outputs]; Nlc = doc.getElementsByTagName ("ynom"); Elements = (Element) Nlc.item(0); s= Elements.getChildNodes().item (0).getNodeValue().trim (); ss=s.split(","); for (int i=0;i<ss.length;i++) this.ynom[i]=Double.valueOf (ss[i].trim()); this.fmax = new double [this.outputs]; Nlc = doc.getElementsByTagName ("fmax"); Elements = (Element) Nlc.item(0); s= Elements.getChildNodes().item (0).getNodeValue().trim (); ss=s.split(","); for (int i=0;i<ss.length;i++) this.fmax[i]=Double.valueOf (ss[i].trim()); // initialise instance variables } catch (Exception e) { System.out.println (e.getMessage()); e.printStackTrace(); } } }
Додаток Б. Програмний код класу Controller import java.util.TimerTask; import java.util.Timer; import java.lang.Math.*; import org.math.array.DoubleArray.*; import static org.math.array.LinearAlgebra.*; import java.io.*; public class Controller extends TimerTask { private static int inputs, outputs, xsize; private static double[][] ad, bd, c, d; private static double[][] ar, br, cr; private static double[][] z, f, u, u1, y, e, x, x1, xr, xr1; private static double[] unom, fmax; private static boolean manual=false; private static boolean work=true; private final String OBJECT_FILE="data/object.xml"; public static boolean getManual() {return manual;} public static void setManual(boolean newVal) {manual=newVal;} public static boolean getWork() {return work;} public static void setWork(boolean newVal) {work=newVal;} public static double getY(int output) {return y[output][0];} public static double getU(int input) {return u[input][0];} public static void setU(double val,int input) {u[input][0]=val;} public static double getZ(int output) {return z[output][0];} public static void setZ(double val,int output) {z[output][0]=val;}
public Controller (int p_inputs, int p_outputs,int p_xsize, double[][] p_ad, double[][] p_bd,double[][] p_c, double[][] p_d, double[][] p_ar, double[][] p_br,double[][] p_cr, double[] p_fmax,double[] p_unom) { this.inputs=p_inputs; this.outputs=p_outputs; this.xsize=p_xsize; this.ar=p_ar; this.ad=p_ad; this.br=p_br; this.bd=p_bd; this.cr=p_cr; this.c=p_c; this.d=p_d; this.fmax=p_fmax; this.unom=p_unom; /** Код ініціалізує поля об'єктта таким чином, щоб розмірності масивів полів збігалися з матрицями об'єкта і регулятора: */ this.z=new double [p_outputs][1]; this.f=new double [p_inputs][1]; this.u=new double [p_inputs][1]; this.u1=new double [p_inputs][1]; this.y=new double [p_outputs][1]; this.e=new double [p_outputs][1]; this.x=new double [this.c[0].length][1]; this.x1=new double [this.c[0].length][1]; this.xr=new double [this.ar[0].length][1]; this.xr1=new double [this.cr[0].length][1]; }
public void run() { if(work) { for(int i=0;i<inputs;i++) f[i][0]=Math.random()*fmax[i];
if(!manual) { e=minus(y,z); u=times(cr,xr); xr=times (ar,xr); xr1=times(br,e); xr=plus(xr,xr1); } x=times(ad,x); u1=plus(u,f); x1=times(bd,u1); x=plus(x,x1); y=times(c,x); } } }
Додаток В. Програмний код класу Application public class Application { public static XMLInterface xml=new XMLInterface(); public static GUI gui=new GUI(); public static java.util.Timer controller=new java.util.Timer();
public Application() { try { int period=(int)(1000*xml.getDt()); controller.schedule (new Controller (xml.getInputs(), xml.getOutputs(),xml.getXsize(),xml.getAd(),xml.getBd(),xml.getC(), xml.getD(),xml.getAr(),xml.getBr(),xml.getCr(),xml.getFmax(), xml.getUnom()), 0,period); } catch (Exception e) { e.printStackTrace(); } } public static void main(String[]args) { new Application(); } }
|
||
|
Последнее изменение этой страницы: 2016-09-20; просмотров: 269; Нарушение авторского права страницы; Мы поможем в написании вашей работы! infopedia.su Все материалы представленные на сайте исключительно с целью ознакомления читателями и не преследуют коммерческих целей или нарушение авторских прав. Обратная связь - 216.73.217.128 (0.005 с.) |