1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209
| using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace simplexessaie
{
public partial class frm : Form
{
public frm()
{
InitializeComponent();
}
static int nbr_con = Convert.ToInt32(txtcon.Value);
static int nbr_var =Convert.ToInt32(txtvar.Text);
// decimal[] Simpl;
decimal Resultat, i, j ;
//int m = (nbr_var + 2) * (nbr_con + 1);
decimal[] z = new decimal[1];
String mot = "";
decimal[] Simpl = new decimal[(nbr_var + 2) * (nbr_con + 1)];
decimal[] sol = new decimal[nbr_var];
decimal[] Donnees = new decimal[(nbr_var + 2) * (nbr_con + 1)];
public void affiche_coefficient(object sender, EventArgs e)
{
int j = 0;
int c = ( nbr_con * 30) + 30;
int k = 0;
int s = 0;
int r = 170;
// lblcoefobj
Label lblcoefobj = new Label();
lblcoefobj.Location = new System.Drawing.Point(7, 104);
lblcoefobj.Size = new System.Drawing.Size(200, 13);
lblcoefobj.Font = new System.Drawing.Font("Microsoft Sans Serif", 7.75F, ((System.Drawing.FontStyle)((System.Drawing.FontStyle.Bold | System.Drawing.FontStyle.Italic))), System.Drawing.GraphicsUnit.Point, ((byte)(0)));
lblcoefobj.Text = "Coefficient de la fonction objectif:";
this.Controls.Add(lblcoefobj);
// lblcoefcon
Label lblcoefcon = new Label();
lblcoefcon.Location = new System.Drawing.Point(7, 200);
lblcoefcon.Size = new System.Drawing.Size(200, 13);
lblcoefcon.Font = new System.Drawing.Font("Microsoft Sans Serif", 7.75F, ((System.Drawing.FontStyle)((System.Drawing.FontStyle.Bold | System.Drawing.FontStyle.Italic))), System.Drawing.GraphicsUnit.Point, ((byte)(0)));
lblcoefcon.Text = "Coefficient des contraintes :";
this.Controls.Add(lblcoefcon);
// lblcoefsemem
Label lblcoefsemem = new Label();
lblcoefsemem.Location = new System.Drawing.Point(7, 130 + c);
lblcoefsemem.Size = new System.Drawing.Size(200, 13);
lblcoefsemem.Font = new System.Drawing.Font("Microsoft Sans Serif", 7.75F, ((System.Drawing.FontStyle)((System.Drawing.FontStyle.Bold | System.Drawing.FontStyle.Italic))), System.Drawing.GraphicsUnit.Point, ((byte)(0)));
lblcoefsemem.Text = "Coefficient de second membre :";
this.Controls.Add(lblcoefsemem);
//
for (int i = 0; i <nbr_var; i++)
{
NumericUpDown CofonctiObjec = new NumericUpDown();
CofonctiObjec.Location = new Point(230 + j, 100);
CofonctiObjec.Size = new System.Drawing.Size(50, 20);
CofonctiObjec.DecimalPlaces=2;
CofonctiObjec.Name = "CofonctiObjec" + i.ToString();
this.Controls.Add(CofonctiObjec);
j += 60;
//listVariable[i] = Convert.ToInt16( (text1.Text as TextBox).Text);
}
do
{
r += 60;
k = 0;
for (int i = 0; i <nbr_con; i++)
{
NumericUpDown CofContrainte = new NumericUpDown();
CofContrainte.Location = new Point(r, 200 + k);
CofContrainte.Size = new System.Drawing.Size(50, 20);
CofContrainte.DecimalPlaces = 2;
CofContrainte.Name = "CofContrainte" + i.ToString();
this.Controls.Add(CofContrainte);
k += 30;
}
s++;
}
while (s <nbr_var);
bool ok = false;
do{
int m = 0;
r += 60;
for (int i = 0; i <nbr_con; i++)
{
ComboBox com = new ComboBox();
com.Location = new Point(r, 200+m);
com.Size = new System.Drawing.Size(50, 21);
com.Name = "com"+i.ToString();
com.Font = new System.Drawing.Font("Arial", 9.75F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
com.FormattingEnabled = true;
com.Items.AddRange(new object[] {
"=>",
"<=",
"="});
/* com.Maximum = new decimal(new int[] {
1000
});*/
com.TabIndex = 13;
this.Controls.Add(com);
NumericUpDown CofSecoMembre = new NumericUpDown();
CofSecoMembre.Location = new Point(r+60, 200 + m);
CofSecoMembre.Size = new System.Drawing.Size(50, 20);
CofSecoMembre.DecimalPlaces = 2;
CofSecoMembre.Name = "CofSecoMembre" + i.ToString();
this.Controls.Add(CofSecoMembre);
// txtContrainte.Name = "txtContrainte" + i.ToString();
m += 30;
}
}
while(ok);
}
public void frm_FormClosing(object sender, FormClosingEventArgs e)
{
DialogResult key = MessageBox.Show("voulez-vous vraiment quitter l'application", "confirmation", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
if (DialogResult.No == key)
e.Cancel = true;
}
public void résoudre_Click_1(object sender, EventArgs e)
{
i = 0;
while (i < nbr_var)
{
Simpl[Convert.ToInt16( (nbr_con * nbr_var )+ 2 + i)] =(this.Controls["CofonctiObjec" + i.ToString()] as NumericUpDown).Value;
i++;
}
i = 0;
while (i <nbr_con)
{
j = 0;
while (j < nbr_var)
{
Simpl[Convert.ToInt16( i * (nbr_var + 2) + j)] =(this.Controls["CofContrainte" + i.ToString()] as NumericUpDown).Value;
j++;
}
Simpl[Convert.ToInt16( i * (nbr_var + 2) + j + 1)] = -1;
try { Simpl[Convert.ToInt16(i * (nbr_var + 2) + j)] = (this.Controls["CofSecoMembre" + i.ToString()] as NumericUpDown).Value; }
catch(Exception ){}
i++;
}
Simplex S = new Simplex();
Resultat = S.Simplexe(Simpl, nbr_var, nbr_con, sol, z, mot);
mot += "\n\t*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-RESULTAT:*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*\n";
if (Resultat != 0)
{
mot += "\nLe probleme admet une solution optimale :\t\n -Z =" + z[0] + "\n\n\tavec\t";
for (i = 0; i < nbr_var; i++)
mot += "\n\n X" + (i + 1) + "=\t" + (sol[Convert.ToInt16(i)]);
mot += "\n";
}
else
mot += "\n\"Le n'admet pas de solution!!!\"";
MessageBox.Show(mot, "DONNEES");
}
public void linkLabel1_Click(object sender, EventArgs e)
{
MessageBox.Show("essaie");
}
}
} |
Partager