top of page

Bulanik Mantik Motor Performans Uygulamasi [C#]

  • Writer: Sevdanur GENC
    Sevdanur GENC
  • Dec 26, 2012
  • 7 min read

Bu makale iceriginde Suleyman Demirel Universitesi – Bilgisayar Muhendisligi bolumu’nun Yapay Zeka dersi icin gelistirilen Bulanik Mantik uygulamasinin .Net'de C# programlama dili ile birlikte grafik ozelligi kullanilarak yapilmis bir ornegini paylasiyor olacagim. Bulanik mantik uzerinde incelemis oldugumuz motor performans uygulamasinin ilgili problemler ve aciklamalari Bulanik Mantik – Motor Performans Uygulamasi isimli makale icerisinde bulabilirsiniz. Simdi dilerseniz uygulamanin tasarim ve kod kisimlarina gecelim.

                  Yukaridaki gibi bir ekran goruntusunu Visual Studio'nun Web Sites proje arayuzunde hazirliyoruz. Hesap butonuna bastiginda kullanicidan alacagi Tork ve Saatlik Yakit Tuketimi degerlerini hesapladiktan sonra asagiya sonuclari yazdiracak. Sonuclarin Sonucunda da gormek istediginiz hangi grafikse onu Grafik Ciz butonlari ile ekrana bastirabilirsiniz. Oncelikle bir grafikciz.aspx web sayfasi olusturuyoruz ve icerigine bir chart nesnesi yerlestiriyoruz. Grafik isminde bir sinif olusturuyoruz ve grafik cizimindeki gerekli kodlari icerisine yaziyoruz.

Grafik.Cs Kaynak Kodlari ;

using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Drawing; using System.Drawing.Drawing2D; using System.Drawing.Imaging; using System.Collections; namespace BMSinavUyg { public class Grafik { public class Line2D { private int m_Width = 700; private int m_Height = 400; private ArrayList m_XAxis; private ArrayList m_YAxis; private Color m_graphColor = Color.Red; private float m_XSlice = 1; private float m_YSlice = 1; private Graphics objGraphics; private Bitmap objBitmap; private string m_XAxisText = ""; private string m_YAxisText = ""; private string m_Title = ""; private Color m_TitleBackColor = Color.Cyan; private Color m_TitleForeColor = Color.Green; public int Width { get { return m_Width; } set { if (value > 200) m_Width = value; } } public int Height { get { return m_Height; } set { if (value > 200) m_Height = value; } } public ArrayList XAxis { set { m_XAxis = value; } get { return m_XAxis; } } public ArrayList YAxis { set { m_YAxis = value; } get { return m_YAxis; } } public Color GraphColor { set { m_graphColor = value; } get { return m_graphColor; } } public float XSlice { set { m_XSlice = value; } get { return m_XSlice; } } public float YSlice { set { m_YSlice = value; } get { return m_YSlice; } } public string XAxisText { get { return m_XAxisText; } set { m_XAxisText = value; } } public string YAxisText { get { return m_YAxisText; } set { m_YAxisText = value; } } public string Title { get { return m_Title; } set { m_Title = value; } } public Color TitleBackColor { get { return m_TitleBackColor; } set { m_TitleBackColor = value; } } public Color TitleForeColor { get { return m_TitleForeColor; } set { m_TitleForeColor = value; } } public Line2D() { } public void InitializeGraph() { objBitmap = new Bitmap(Width, Height); objGraphics = Graphics.FromImage(objBitmap); objGraphics.FillRectangle(new SolidBrush(Color.LightGray), 0, 0, Width, Height); objGraphics.DrawLine(new Pen(new SolidBrush(Color.Black), 2), 10, Height - 100, Width - 10, Height - 100); objGraphics.DrawLine(new Pen(new SolidBrush(Color.Black), 2), 10, Height - 100, 10, 125); objGraphics.DrawString("0", new Font("Courier New", 10), new SolidBrush(Color.White), 0, Height - 90); SetAxisText(ref objGraphics); CreateTitle(ref objGraphics); } public void CreateGraph(Color _GraphColor) { GraphColor = _GraphColor; SetPixels(ref objGraphics); } public Bitmap GetGraph() { SetXAxis(ref objGraphics, XSlice); SetYAxis(ref objGraphics, YSlice); return objBitmap; } private void PlotGraph(ref Graphics objGraphics, float x1, float y1, float x2, float y2) { objGraphics.DrawLine(new Pen(new SolidBrush(GraphColor), 2), x1 + 10, (Height - 100) - y1, x2 + 10, (Height - 100) - y2); } private void SetXAxis(ref Graphics objGraphics, float iSlices) { float x1 = 10, y1 = Height - 110, x2 = 10, y2 = Height - 90; int iCount = 0; int iSliceCount = 1; for (int iIndex = 0; iIndex <= Width; iIndex += 10) { if (iCount == 2) { objGraphics.DrawLine(new Pen(new SolidBrush(Color.Black)), x1 + iIndex, y1, x2 + iIndex, y2); objGraphics.DrawString(Convert.ToString(iSlices * iSliceCount), new Font("verdana", 8), new SolidBrush(Color.White), x1 + iIndex - 10, y2); iCount = 0; iSliceCount++; } else { objGraphics.DrawLine(new Pen(new SolidBrush(Color.Goldenrod)), x1 + iIndex, y1 + 5, x2 + iIndex, y2 - 5); } iCount++; } } private void SetYAxis(ref Graphics objGraphics, float iSlices) { int x1 = 5; int y1 = Height - 110; int x2 = 15; int y2 = Height - 110; int iCount = 1; int iSliceCount = 1; for (int iIndex = 0; iIndex < Height - 250; iIndex += 10) { if (iCount == 5) { objGraphics.DrawLine(new Pen(new SolidBrush(Color.Black)), x1 - 5, y1 - iIndex, x2 + 5, y2 - iIndex); objGraphics.DrawString(Convert.ToString(iSlices * iSliceCount), new Font("verdana", 8), new SolidBrush(Color.White), 20, y1 - iIndex); iCount = 0; iSliceCount++; } else { objGraphics.DrawLine(new Pen(new SolidBrush(Color.Goldenrod)), x1, (y1 - iIndex), x2, (y2 - iIndex)); } iCount++; } } private void SetPixels(ref Graphics objGraphics) { float X1 = float.Parse(XAxis<0>

.ToString()); float Y1 = float.Parse(YAxis<0>

.ToString()); if (XAxis.Count == YAxis.Count) { for (int iXaxis = 0, iYaxis = 0; (iXaxis < XAxis.Count - 1 && iYaxis < YAxis.Count - 1); iXaxis++, iYaxis++) { PlotGraph(ref objGraphics, X1, Y1, float.Parse(XAxis

.ToString()), float.Parse(YAxis

.ToString())); X1 = float.Parse(XAxis

.ToString()); Y1 = float.Parse(YAxis

.ToString()); } } else { } } private void SetAxisText(ref Graphics objGraphics) { objGraphics.DrawString(XAxisText, new Font("Courier New", 10), new SolidBrush(Color.LimeGreen), Width / 2 - 50, Height - 50); int X = 30; int Y = (Height / 2) - 50; for (int iIndex = 0; iIndex < YAxisText.Length; iIndex++) { objGraphics.DrawString(YAxisText

.ToString(), new Font("Courier New", 10), new SolidBrush(Color.LimeGreen), X, Y); Y += 20; } } private void CreateTitle(ref Graphics objGraphics) { objGraphics.FillRectangle(new SolidBrush(TitleBackColor), Height - 100, 20, Height - 200, 20); Rectangle rect = new Rectangle(Height - 100, 20, Height - 200, 20); objGraphics.DrawString(Title, new Font("Verdana", 10), new SolidBrush(TitleForeColor), rect); } } } }

SabitKullanilan.Cs Kaynak Kodlari ;

using System; using System.Collections.Generic; using System.Linq; using System.Web; namespace BMSinavUyg { public class SabitKullanilan { public static string QueryStringGetir(string ifade) { string deger = HttpContext.Current.Request.QueryString

; if (string.IsNullOrEmpty(deger)) return null; return deger; } public static string PopupWindowOlustur(string sayfaUri, string genislik, string yukseklik) { return string.Format( "javascript:var a = window.open(\"{0}\",null,\"width={1},height={2},top=100,left=5,scrollbars=1 \");", sayfaUri, genislik, yukseklik ); } } }

GrafikCiz.Aspx.Cs Kaynak Kodlari ;

using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using System.ComponentModel; using System.Data; using System.Drawing; using System.Web.SessionState; using System.Web.UI.HtmlControls; using System.Drawing.Imaging; using System.Collections; namespace BMSinavUyg { public partial class GrafikCiz : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { var ad = SabitKullanilan.QueryStringGetir("Ad"); var a1 = SabitKullanilan.QueryStringGetir("A"); var g1 = SabitKullanilan.QueryStringGetir("G"); Grafik.Line2D line2d = new Grafik.Line2D(); double a, b, c, d, f, g, k; a = Convert.ToDouble(a1); g = Convert.ToDouble(g1); b = a+g; c = b+g; d =c+g; f =d+g; line2d.Height = 350; line2d.Width = 450; line2d.XSlice = 2; line2d.YSlice = 1; line2d.Title =ad; line2d.TitleBackColor = Color.Linen; line2d.TitleForeColor = Color.HotPink; line2d.InitializeGraph(); ArrayList arX = new ArrayList(); ArrayList arY = new ArrayList(); arX.Add(a); arX.Add(b); arY.Add(0); arY.Add(50); line2d.XAxis = arX; line2d.YAxis = arY; line2d.CreateGraph(Color.Green); arX = new ArrayList(); arY = new ArrayList(); arX.Add(a); arX.Add(b); arY.Add(50); arY.Add(0); line2d.XAxis = arX; line2d.YAxis = arY; line2d.CreateGraph(Color.Red); arX = new ArrayList(); arY = new ArrayList(); arX.Add(b); arX.Add(c); arY.Add(0); arY.Add(50); line2d.XAxis = arX; line2d.YAxis = arY; line2d.CreateGraph(Color.Yellow); arX = new ArrayList(); arY = new ArrayList(); arX.Add(b); arX.Add(c); arY.Add(50); arY.Add(0); line2d.XAxis = arX; line2d.YAxis = arY; line2d.CreateGraph(Color.Green); arX = new ArrayList(); arY = new ArrayList(); arX.Add(c); arX.Add(d); arY.Add(0); arY.Add(50); line2d.XAxis = arX; line2d.YAxis = arY; line2d.CreateGraph(Color.Blue); arX = new ArrayList(); arY = new ArrayList(); arX.Add(c); arX.Add(d); arY.Add(50); arY.Add(0); line2d.XAxis = arX; line2d.YAxis = arY; line2d.CreateGraph(Color.Yellow); arX.Add(d); arX.Add(f); arY.Add(0); arY.Add(50); line2d.XAxis = arX; line2d.YAxis = arY; line2d.CreateGraph(Color.Brown); arX = new ArrayList(); arY = new ArrayList(); arX.Add(d); arX.Add(f); arY.Add(50); arY.Add(0); line2d.XAxis = arX; line2d.YAxis = arY; line2d.CreateGraph(Color.Blue); Bitmap bmp = line2d.GetGraph(); bmp.Save(Response.OutputStream, ImageFormat.Jpeg); bmp.Dispose(); } } }

MotorPerformansHesaplama.Aspx Kaynak Kodlari ;

<%@ Page Title="" Language="C#" MasterPageFile="~/Sinav.Master" AutoEventWireup="true" CodeBehind="MotorPerformansHesaplama.aspx.cs" Inherits="BMSinavUyg.MotorPerformansHesaplama" %> <asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" runat="server"> <style type="text/css"> .style1 {            width: 166px;        } </style> </asp:Content> <asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder2" runat="server"> <table style="text-align: left; height: 191px; width: 704px"> <tr>            <td>                <asp:Label ID="Label1" runat="server" Text="Tork"></asp:Label> &nbsp;

</td> <td>                <asp:TextBox ID="TxtTork" runat="server" Width="250px"></asp:TextBox> &nbsp;<0 - 23 >

</td>        </tr> <tr>            <td>                <asp:Label ID="Label2" runat="server" Text="Saatlik yakıt tüketimi "></asp:Label>

</td>            <td> <asp:TextBox ID="TxtSaYaTuk" runat="server" Width="250px"></asp:TextBox> &nbsp;<2 - 12 kg / h>

</td> </tr>        <tr> <td>                <asp:Button ID="BtnHesapla" runat="server" Text="Hesaplama" Width="250px" onclick="BtnHesapla_Click" /></td> </tr>        <tr>            <td>                Motor Performans</td>            <td> <asp:TextBox ID="TxtMp" runat="server" Width="246px"></asp:TextBox> &nbsp;<15 - 40 kw>

</td> </tr>        <tr>            <td>                <asp:Label ID="Label5" runat="server" Text="Sonuc "></asp:Label> </td>            <td>                <asp:TextBox ID="TxtSonuc" runat="server" Width="246px"></asp:TextBox> </td>          </tr>        <tr> <td>                Tort Grafikleri</td>            <td> <asp:Button ID="BtnTorkGrafikCiz" runat="server" Text="Grafik Ciz" Width="250px" />            </td>        </tr>        <tr            <td> Saatlik Yakit Tuketimi Grafikleri</td>            <td> <asp:Button ID="BtnSatYakTukGrafikCiz" runat="server" Text="Grafik Ciz" Width="250px" />            </td>        </tr>        <tr>            <td> Motor Referansi Grafikleri</td>            <td> <asp:Button ID="BtnMotRefGrafikCiz" runat="server" Text="Grafik Ciz" Width="250px" />            </td>        </tr>    </table> </asp:Content>

MotorPerformansHesaplama.Aspx.Cs Kaynak Kodlari ;

using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using System.Drawing; using System.Drawing.Imaging; namespace BMSinavUyg { public partial class MotorPerformansHesaplama : System.Web.UI.Page { enum derece { CokDusuk, Dusuk, Normal, Yuksek, CokYuksek }; public double Tork; public double Syt; public string Mp; public string Sonuc; public double TorkSon; public double Ort; public double MotorP; public double SytSon; public string MotorPerformans() { Tork = Convert.ToDouble(TxtTork.Text); Syt = Convert.ToDouble(TxtSaYaTuk.Text); TorkMd(); SaatYakitTuketimi(); Ort=((SytSon*0.3)+(TorkSon*0.7))/2; MotorP=((10+(Syt*(6.25/2.5)))+(15+(Tork*(6.25/5.75))))/2; Console.WriteLine(Tork); if (Ort<=0.5) { if (MotorP<18) { Mp=" cok yuksek"; return Mp; } if (MotorP>=18 && MotorP<24) { Mp="yuksek"; return Mp; } if (MotorP>=24 && MotorP<31) { Mp="orta"; return Mp; } if (MotorP>=31 && MotorP<37) { Mp="dusuk"; return Mp; } if (MotorP>=37 ) { Mp="cok dusuk"; return Mp; } } if (Ort>0.5) { if (MotorP<21) { Mp="cok yuksek"; return Mp; } if (MotorP>=21 && MotorP<27) { Mp="yuksek"; return Mp; } if (MotorP>=27 && MotorP<34) { Mp="orta"; return Mp; } if (MotorP>=34) { Mp="dusuk"; return Mp; } } return Mp; } public double TorkMd() { Tork = Convert.ToDouble(TxtTork.Text); if (Tork < 5.75) { TorkSon = ((5.75 - Tork) / 5.75); return TorkSon; } if (Tork < 11.5 && Tork >= 5.75) { TorkSon = ((11.5 - Tork) / 5.75); return TorkSon; } if (Tork < 17.25 && Tork >= 11.5) { TorkSon = ((17.25 - Tork) / 5.75); return TorkSon; } if (Tork < 23 && Tork >= 17.25) { TorkSon = ((23 - Tork) / 5.75); return TorkSon; } return Convert.ToDouble(null); } public double SaatYakitTuketimi() { Syt = Convert.ToDouble(TxtSaYaTuk.Text); if (Syt < 4.5) { SytSon = ((4.5 - Syt) / 2.5); return SytSon; } if (Syt < 7 && Syt >= 4.5) { SytSon = ((7 - Syt) / 2.5); return SytSon; } if (Syt < 17.25 && Syt >= 7) { SytSon = ((17.25 - Syt) / 2.5); return SytSon; } if (Syt < 23 && Syt >= 17.25) { SytSon = ((23 - Syt) / 2.5); return SytSon; } return Convert.ToDouble(null); } protected void Page_Load(object sender, EventArgs e) { string url = ResolveClientUrl("GrafikCiz.aspx"); BtnTorkGrafikCiz.OnClientClick = SabitKullanilan.PopupWindowOlustur(url + "?A=" + 0 + "&G=" + 57.5 + "&Ad=" + "Tork" , "400", "400"); BtnSatYakTukGrafikCiz.OnClientClick = SabitKullanilan.PopupWindowOlustur(url + "?A=" + 20 + "&G=" + 25 + "&Ad=" + "Saat Yakıt Tüketimi","400", "400"); BtnMotRefGrafikCiz.OnClientClick = SabitKullanilan.PopupWindowOlustur(url + "?A=" + 150 + "&G=" +62.5 + "&Ad=" + "Motor Performans", "400", "400"); } protected void BtnHesapla_Click(object sender, EventArgs e) { MotorPerformans(); TxtSonuc.Text = Mp; TxtMp.Text = Convert.ToString(MotorP); } } }

Uygulamanin Ekran Goruntuleri ;

                Hesaplamalardan Sonra Tork Grafigini cizdirelim;

                  Saatlik Yakit Tukerimi Grafigini cizdirelim ;

Recent Posts

See All
Oracle Java Cloud Service Uygulamasi

Bir onceki Oracle Cloud Computing yazisinda bahsettigim gibi JDeveloper Oracle Cloud icin gelistirmis oldugu surumu olan Oracle JDeveloper 11g (11.1.1.6.0) ile kucuk bir uygulama gelistirip bunu oracl

 
 
 
Oracle Cloud Computing Hakkinda

Bulut bilisim konusundaki arastirmalarima devam ederken bu kez solugu Oracle Cloud Computing'de aldim. Bu makalem ve ilerleyen makalelerimde Trial versiyonu ile user tarafini pek yormayan bir yapidan

 
 
 
Nested Parallel Loops

Matrix Multiplication / Matrix Carpma islemlerini OpenMP araciligi ile paralel alanda nasil yapilabilecegini incelerken ayni zamanda for construct'larin nested parallel loops alaninda nasil calistigin

 
 
 

Comments


©2035 by Sevdanur Genc. Powered and secured by Wix

bottom of page