0

我想优化 c# 中的非线性函数,12 或 15 个变量(视情况而定)。它受到两个非线性不等式和四个线性不等式的约束。我已经尝试使用 ALGLIB 曲目的 AUL(增广拉氏)方法。不幸的是,算法收敛到错误的最小值。我认为这是因为我想不出可行解决方案的初步猜测。

有谁知道解决这个问题的方法?非常感谢。

PS:本人不会说英文,如有错误请见谅!

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace TestDefinitionFct
{
class Program
{
    public static int Main(string[] args)
    {


        //Tentative de minimisation

        double[] CA = new double[] { };
        double[] CE = new double[] { };
        double[] CD = new double[] { };
        double[] CF = new double[] { };



        double epsx;
        double epsf;
        double epsg;
        int outerits=5;
        double rho;
        int maxits;
        double diffstep = 0.000000001;
        alglib.minnlcstate state;
        alglib.minnlcreport rep;
        double[] x1;


        Console.WriteLine("Problème à combien de pièces?");
        Console.WriteLine("Cas 4_3P");
        string saisie = Console.ReadLine();

        switch (saisie)
        {
            case "2":
                double[] x0_2P = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
                double[] s_2P = { 1, 1, 1, 1, 1, 1, 1, 100, 100, 100, 100, 100 };
                epsx = 0.00001;
                epsg = 0.00001;
                epsf = 0.00001;
                int updatefreq = 10;

                rho = 1000.0;
                maxits = 0;
                alglib.minnlccreatef(12, x0_2P,diffstep, out state);
                alglib.minnlcsetalgoaul(state, rho, outerits);
                alglib.minnlcsetcond(state, epsg, epsf, epsx, maxits);
                alglib.minnlcsetscale(state, s_2P);
                alglib.minnlcsetprecexactlowrank(state, updatefreq);
                alglib.minnlcsetnlc(state, 0, 6);
                alglib.minnlcoptimize(state, Nlcfunc2_2P, null, null);
                alglib.minnlcresults(state, out x1, out rep);
                for (int i=0;i<=6;i++)
                {
                    x1[i] = x1[i] % (2 * 3.141592654); //ATTENTION

                }

                System.Console.WriteLine("{0}", alglib.ap.format(x1, 2)); 
                System.Console.ReadLine();


                break;
            case "3":
                double[] x0_3P = { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 };
                double[] s_3P = { 1, 1, 1, 1, 1, 1, 1, 1, 1, 100, 100, 100, 100, 100, 100};
                epsx = 0.0000001;
                epsg = 0.0000001;
                epsf = 0.0000001;
                updatefreq = 10;
                outerits = 0;
                rho = 1000.0;
                maxits = 0;
                alglib.minnlccreatef(15, x0_3P, diffstep, out state);
                alglib.minnlcsetalgoaul(state, rho, outerits);
                alglib.minnlcsetcond(state, epsg, epsf, epsx, maxits);
                alglib.minnlcsetscale(state, s_3P);
                alglib.minnlcsetprecexactlowrank(state, updatefreq);
                alglib.minnlcsetnlc(state, 0, 6);
                alglib.minnlcoptimize(state, Nlcfunc2_3P, null, null);
                alglib.minnlcresults(state, out x1, out rep);

                for (int i = 0; i <= 9; i++)
                {
                    x1[i] = x1[i] % (2 * 3.141592654); //ATTENTION

                }
                System.Console.WriteLine(alglib.ap.format(x1, 2));
                System.Console.ReadLine();
                break;


        }

        return (0);

    }

 public static void Nlcfunc2_2P(double[] x, double[] fi, object obj)  //cas 0_2P
    {

        double A01 = x[0], A02 = x[1], A11 = x[2], A13 = x[3], AA = x[4], AD = x[5], AT = x[6], LA = x[7], LD = x[8], X1 = x[9], X2 = x[10], X3 = x[11];

        double t0, /*t1,*/ t2, t3, t4, t5, t6, t7, t8, t9, t10, t11, t12, t13, t14, t15, t16, t17, t18, t19, t20, t21, t22, t23, t24, t25, t26, t27, t28, t29, t30, t31, t32, t33, t34, t35, t36, t37, t38, t39, t40, t41, t42, t43, t44, t45, t46, t47, t48, t49, t50;
        double t51, t52, t53, t54, t55, t56, t57, t58, t59, t60, t61, t62, t63, t64, t65, t66, t67, t68, t69, t70, t71, t72, t73, t74, t75, t76, t77, t78, t79, t80, t81, t82, t83, t84, t85, t86, t87, t88, t89, t90, t91, t92, t93, t94, t95, t96, t97, t98, t99, t100;
        double t101, t102, t103, t104, t105, t106, t107, t108, t109, t110, t111, t112, t113, t114, t115, t116, t117, t118, t119, t120, t121, t122, t123, t124, t125, t126, t127, t128, t129, t130, t131, t132, t133, t134, t135, t136, t137, t138, t139, t140, t141, t142, t143, t144, t145, t146, t147, t148, t149, t150;
        double t151, t152, t153, t154, t155, t156, t157, t158, t159, t160, t161, t162, t163, t164, t165, t166, t167, t168, t169, t170, t171, t172, t173, t174, t175, t176, t177, t178, t179, t180, t181, t182, t183, t184, t185, t186, t187, t188, t189, t190, t191, t192, t193, t194, t195, t196, t197, t198, t199, t200;
        double t201, t202, t203, t204, t205, t206, t207, t208, t209, t210, t211, t212, t213, t214, t215, t216, t217, t218, t219, t220, t221, t222, t223, t224, t225, t226, t227, t228, t229, t230, t231, t232, t233, t234, t235, t236, t237, t238, t239, t240, t241, t242, t243, t244, t245, t246, t247, t248, t249, t250;
        double t251, t252, t253, t254, t255, t256, t257, t258, t259, t260, t261, t262, t263, t264, t265, t266, t267, t268, t269, t270, t271, t272, t273, t274, t275, t276, t277, t278, t279, t280, t281, t282, t283, t284, t285, t286, t287, t288, t289, t290, t291, t292, t293, t294, t295, t296, t297, t298, t299, t300;
        double t301, t302, t303, t304, t305, t306, t307, t308, t309, t310, t311, t312, t313, t314, t315, t316, t317, t318, t319, t320, t321, t322, t323, t324, t325, t326, t327, t328, t329, t330, t331, t332, t333, t334, t335, t336, t337, t338, t339, t340, t341, t342, t343, t344, t345, t346, t347, t348, t349, t350, t351, t352, t353, t354, t355, t356, t357, t358, t359, t360, t361, t362, t363, t364, t365, t366, t367, t368, t369, t370, t371, t372, t373, t374, t375, t376, t377, t378, t379, t380, t381, t382, t383, t384, t385, t386, t387, t388, t389, t390, t391, t392, t393, t394, t395, t396, t397, t398, t399, t400, t401, t402, t403, t404, t405, t406, t407, t408, t409, t410, t411, t412, t413, t414, t415, t416, t417, t418, t419, t420, t421, t422, t423, t424, t425, t426, t427, t428, t429, t430, t431, t432, t433, t434, t435, t436, t437, t438, t439, t440, t441, t442, t443, t444, t445, t446, t447, t448, t449, t450;
        double t451, t452, t453, t454, t455, t456, t457, t458, t459, t460, t461, t462, t463, t464, t465, t466, t467, t468, t469, t470, t471, t472, t473, t474, t475, t476, t477, t478, t479, t480, t481, t482, t483, t484, t485, t486, t487, t488, t489, t490, t491, t492, t493, t494, t495, t496, t497, t498, t499, t500, t501, t502, t503, t504, t505, t506, t507, t508, t509, t510, t511, t512, t513, t514, t515, t516, t517, t518, t519, t520, t521, t522, t523, t524, t525, t526, t527, t528, t529, t530, t531, t532, t533, t534, t535, t536, t537, t538, t539, t540, t541, t542, t543, t544, t545, t546, t547, t548, t549, t550, t551, t552, t553, t554, t555, t556, t557, t558, t559, t560, t561, t562, t563, t564, t565, t566, t567, t568, t569, t570, t571, t572, t573, t574, t575, t576, t577, t578, t579, t580, t581, t582, t583, t584, t585, t586, t587, t588, t589, t590, t591, t592, t593, t594, t595, t596, t597, t598, t599, t600;
        double t601, t602, t603, t604, t605, t606, t607, t608, t609, t610, t611, t612, t613, t614, t615, t616, t617, t618, t619, t620, t621, t622, t623, t624, t625, t626, t627, t628, t629, t630, t631, t632, t633, t634, t635, t636, t637, t638, t639, t640, t641, t642, t643, t644, t645, t646, t647, t648, t649, t650, t651, t652, t653, t654, t655, t656, t657, t658, t659, t660, t661, t662, t663, t664, t665, t666, t667, t668, t669, t670, t671, t672, t673, t674, t675, t676, t677, t678, t679, t680, t681, t682, t683, t684, t685, t686, t687, t688, t689, t690, t691, t692, t693, t694, t695, t696, t697, t698, t699, t700, t701, t702, t703, t704, t705, t706, t707, t708, t709, t710, t711, t712, t713, t714, t715, t716, t717, t718, t719, t720, t721, t722, t723, t724, t725, t726, t727, t728, t729, t730, t731, t732, t733, t734, t735, t736, t737, t738, t739, t740, t741, t742, t743, t744, t745, t746, t747, t748, t749, t750;
        double t751, t752, t753, t754, t755, t756, t757, t758, t759, t760, t761, t762, t763, t764, t765, t766, t767, t768, t769, t770, t771, t772, t773, t774, t775, t776, t777, t778, t779, t780, t781, t782, t783, t784, t785, t786, t787, t788, t789, t790, t791, t792, t793, t794, t795, t796, t797, t798, t799, t800, t801, t802, t803, t804, t805, t806, t807, t808, t809, t810, t811, t812, t813, t814, t815, t816, t817, t818, t819, t820, t821, t822, t823, t824, t825, t826, t827, t828, t829, t830, t831, t832, t833, t834, t835, t836, t837, t838, t839, t840, t841, t842, t843, t844, t845, t846, t847, t848, t849, t850, t851, t852, t853, t854, t855, t856, t857, t858, t859, t860, t861, t862, t863, t864, t865, t866, t867, t868, t869, t870, t871, t872, t873, t874, t875, t876, t877, t878, t879, t880, t881, t882, t883, t884, t885, t886, t887, t888, t889, t890, t891, t892, t893, t894, t895, t896, t897, t898, t899, t900, t901, t902, t903, t904, t905, t906, t907, t908, t909, t910, t911, t912, t913, t914, t915, t916, t917, t918, t919, t920, t921, t922, t923, t924, t925, t926, t927, t928, t929, t930, t931, t932, t933, t934;

        double A1X_Max = Math.PI/90.0; //tolérance à définir


        //Definition de F1_2P
        t2 = cos(AD);
        t3 = sin(AD);
        t4 = 3.141592653589793 * (3.0 / 4.0);
        t5 = A13 + t4;
        t6 = t2 * 4.193100990166504E-17;
        t7 = t3 * 1.789310017978022E-18;
        t8 = t6 + t7 + 6.56059089159579E-1;
        t9 = cos(t5);
        t10 = sin(A02);
        t11 = t2 * 7.54660080853734E-1;
        t12 = t3 * 8.639091210190649E-3;
        t13 = t11 + t12 - 3.641859531497865E-17;
        t14 = t10 * t13;
        t15 = cos(A02);
        t16 = t2 * 8.639091210190649E-3;
        t17 = t3 * 7.54660080853734E-1;
        t18 = t16 - t17;
        t19 = t14 - t15 * t18;
        t20 = cos(AA);
        t21 = sin(AA);
        t22 = sin(t5);
        t23 = A11 + t4;
        t24 = cos(t23);
        t25 = sin(t23);
        t26 = t20 * 3.017878881450192E-18;
        t27 = t21 * 1.628054468477683E-16;
        t28 = t26 + t27 + 2.64162327796772E-1;
        t29 = t24 * t24;
        t30 = t25 * t25;
        t31 = t29 + t30;
        t32 = 1.0 / t31;
        t34 = t22 * 9.5E1;
        t35 = t34 - 9.5E1;
        t38 = t25 * t32 * 4.9E1;
        t39 = t38 + 4.9E1;
        t50 = sin(A01);
        t51 = cos(A01);
        t33 = fabs(LA * (-2.64162327796772E-1) - LD * 6.56059089159579E-1 + t2 * 1.536816356579538E-10 + t3 * 7.250889282579535E-12 + t20 * 3.845285197901728E-12 + t21 * 2.069835466291373E-11 - X2 * t8 - X1 * t28 - t9 * t19 * 9.5E1 + t8 * t35 - t28 * t39 - X3 * (t9 * t19 - t8 * t22) + t24 * t32 * (t51 * (t20 * 1.76163991133662E-1 + t21 * 9.482534011543849E-1) - t50 * (t20 * (-9.482534011543849E-1) + t21 * 1.76163991133662E-1 + 1.466395492792771E-17)) * 4.9E1 + 1.30604396262872E2);
        t36 = t2 * 1.734573094623198E-18;
        t49 = t3 * 5.55778172793303E-17;
        t37 = t36 - t49 + 1.31670187018151E-2;
        t40 = t20 * 1.081543440204188E-16;
        t41 = t21 * (-3.611241739452281E-17) + t40 + 7.37474297704441E-1;
        t42 = t3 * 9.99913311051766E-1;
        t43 = t42 + 7.309163664212581E-19;
        t44 = t10 * t43;
        t45 = t2 * 9.99913311051766E-1;
        t46 = t3 * 2.24392928326991E-19;
        t47 = t45 - t46;
        t48 = t44 - t15 * t47;
        t52 = fabs(LA * 7.37474297704441E-1 + LD * 1.31670187018151E-2 - t2 * 7.275326869070457E-12 + t3 * 2.037091523339728E-10 - t20 * 1.302530437361044E-11 + t21 * 6.904210835003301E-12 + X2 * t37 + X1 * t41 - t9 * t48 * 9.5E1 - t35 * t37 + t39 * t41 - X3 * (t9 * t48 + t22 * t37) + t24 * t32 * (t50 * (t20 * 3.16302503904299E-1 + t21 * 5.967280672544279E-1 + 4.093804726903688E-17) - t51 * (t20 * 5.96728067254428E-1 - t21 * 3.16302503904299E-1)) * 4.9E1 - 1.255585652384819E2);
        t53 = t2 * 3.648589206022503E-17;
        t54 = t3 * 5.858760529779916E-19;
        t55 = t53 + t54 - 7.545946601650509E-1;
        t56 = t2 * 6.56115967162692E-1;
        t57 = t3 * (-9.936623398114391E-3) + t56 + 4.188841829872175E-17;
        t58 = t10 * t57;
        t59 = t2 * 9.936623398114391E-3;
        t60 = t3 * 6.56115967162692E-1;
        t61 = t59 + t60;
        t62 = t15 * t61;
        t63 = t58 + t62;
        t64 = t20 * 1.296043728178216E-16;
        t65 = t21 * 2.63446951691103E-17;
        t66 = t64 + t65 - 6.21570530831645E-1;
        t67 = fabs(LA * 6.21570530831645E-1 - LD * 7.545946601650509E-1 - t2 * 1.337407135284847E-10 - t3 * 2.749515348226771E-12 + t20 * 1.70883369744439E-11 + t21 * 6.04995722798309E-13 + X2 * t55 - X1 * t66 + t9 * t63 * 9.5E1 - t35 * t55 - t39 * t66 + X3 * (t9 * t63 - t22 * t55) + t24 * t32 * (t51 * (t20 * 7.82867716781484E-1 + t21 * 2.771665966547862E-2) + t50 * (t20 * 2.771665966547858E-2 - t21 * 7.82867716781484E-1 + 3.450409573788865E-17)) * 4.9E1 - 8.34536574378895E2);
        t0 = sqrt(t33 * t33 + t52 * t52 + t67 * t67);


        fi[0] = t0;

        //Définition de G1_2P

        t2 = cos(AD);
        t3 = sin(AD);
        t4 = 3.141592653589793 * (3.0 / 4.0);
        t5 = A13 + t4;
        t6 = cos(AA);
        t7 = sin(AA);
        t8 = A11 + t4;
        t9 = cos(t8);
        t10 = sin(t8);
        t11 = t9 * t9;
        t12 = t10 * t10;
        t13 = t11 + t12;
        t14 = 1.0 / t13;
        t15 = sin(A01);
        t16 = cos(A01);
        t82 = t6 * 3.16302503904299E-1;
        t83 = t7 * 5.967280672544279E-1;
        t84 = t82 + t83 + 4.093804726903688E-17;
        t85 = t15 * t84;
        t86 = t6 * 5.96728067254428E-1;
        t87 = t7 * 3.16302503904299E-1;
        t88 = t86 - t87;
        t89 = t16 * t88;
        t90 = t85 - t89;
        t91 = t9 * t14 * t90;
        t92 = t6 * 1.081543440204188E-16;
        t93 = t7 * 3.611241739452281E-17;
        t94 = t92 - t93 + 7.37474297704441E-1;
        t95 = t10 * t14 * t94;
        t96 = t91 + t95;
        t17 = fabs(t96);
        t18 = t7 * 1.76163991133662E-1;
        t98 = t6 * 9.482534011543849E-1;
        t19 = t18 - t98 + 1.466395492792771E-17;
        t20 = t6 * 1.76163991133662E-1;
        t21 = t7 * 9.482534011543849E-1;
        t22 = t20 + t21;
        t99 = t15 * t19;
        t100 = t16 * t22;
        t23 = t99 - t100;
        t24 = t9 * t14 * t23;
        t25 = t6 * 3.017878881450192E-18;
        t26 = t7 * 1.628054468477683E-16;
        t27 = t25 + t26 + 2.64162327796772E-1;
        t28 = t10 * t14 * t27;
        t29 = t24 + t28;
        t30 = fabs(t29);
        t52 = t6 * 1.296043728178216E-16;
        t53 = t7 * 2.63446951691103E-17;
        t54 = t52 + t53 - 6.21570530831645E-1;
        t55 = t10 * t14 * t54;
        t56 = t6 * 7.82867716781484E-1;
        t57 = t7 * 2.771665966547862E-2;
        t58 = t56 + t57;
        t59 = t16 * t58;
        t60 = t6 * 2.771665966547858E-2;
        t61 = t7 * 7.82867716781484E-1;
        t62 = t60 - t61 + 3.450409573788865E-17;
        t63 = t15 * t62;
        t64 = t59 + t63;
        t65 = t9 * t14 * t64;
        t66 = t55 - t65;
        t31 = fabs(t66);
        t32 = sin(t5);
        t33 = cos(t5);
        t34 = sin(A02);
        t35 = cos(A02);
        t105 = t2 * 1.734573094623198E-18;
        t106 = t3 * 5.55778172793303E-17;
        t107 = t105 - t106 + 1.31670187018151E-2;
        t108 = t32 * t107;
        t109 = t3 * 9.99913311051766E-1;
        t110 = t109 + 7.309163664212581E-19;
        t111 = t34 * t110;
        t112 = t2 * 9.99913311051766E-1;
        t113 = t3 * 2.24392928326991E-19;
        t114 = t112 - t113;
        t115 = t35 * t114;
        t116 = t111 - t115;
        t117 = t33 * t116;
        t118 = t108 + t117;
        t36 = fabs(t118);
        t67 = t2 * 3.648589206022503E-17;
        t68 = t3 * 5.858760529779916E-19;
        t69 = t67 + t68 - 7.545946601650509E-1;
        t70 = t32 * t69;
        t71 = t2 * 6.56115967162692E-1;
        t72 = t3 * 9.936623398114391E-3;
        t73 = t71 - t72 + 4.188841829872175E-17;
        t74 = t34 * t73;
        t75 = t2 * 9.936623398114391E-3;
        t76 = t3 * 6.56115967162692E-1;
        t77 = t75 + t76;
        t78 = t35 * t77;
        t79 = t74 + t78;
        t80 = t33 * t79;
        t81 = t70 - t80;
        t37 = fabs(t81);
        t38 = t2 * 7.54660080853734E-1;
        t39 = t3 * 8.639091210190649E-3;
        t40 = t38 + t39 - 3.641859531497865E-17;
        t41 = t34 * t40;
        t42 = t2 * 8.639091210190649E-3;
        t43 = t3 * 7.54660080853734E-1;
        t44 = t42 - t43;
        t121 = t35 * t44;
        t45 = t41 - t121;
        t46 = t33 * t45;
        t47 = t2 * 4.193100990166504E-17;
        t48 = t3 * 1.789310017978022E-18;
        t49 = t47 + t48 + 6.56059089159579E-1;
        t122 = t32 * t49;
        t50 = t46 - t122;
        t51 = fabs(t50);
        t97 = t17 * t17;
        t101 = t30 * t30;
        t102 = t31 * t31;
        t103 = t97 + t101 + t102;
        t104 = 1.0 / sqrt(t103);
        t119 = t36 * t36;
        t120 = t37 * t37;
        t123 = t51 * t51;
        t124 = t119 + t120 + t123;
        t125 = 1.0 / sqrt(t124);
        t0 = -t29 * t50 * t104 * t125 - t66 * t81 * t104 * t125 + t96 * t104 * t118 * t125;







        fi[1] = t0;

        //Définition de G2_2P
        t2 = 3.141592653589793 * (3.0 / 4.0);
        t3 = A13 + t2;
        t4 = cos(AD);
        t5 = sin(AD);
        t6 = cos(AA);
        t7 = sin(AA);
        t8 = A11 + t2;
        t9 = cos(t8);
        t10 = sin(t8);
        t11 = t9 * t9;
        t12 = t10 * t10;
        t13 = t11 + t12;
        t14 = 1.0 / t13;
        t15 = sin(A01);
        t16 = cos(A01);
        t82 = t6 * 3.16302503904299E-1;
        t83 = t7 * 5.967280672544279E-1;
        t84 = t82 + t83 + 4.093804726903688E-17;
        t85 = t15 * t84;
        t86 = t6 * 5.96728067254428E-1;
        t87 = t7 * 3.16302503904299E-1;
        t88 = t86 - t87;
        t89 = t16 * t88;
        t90 = t85 - t89;
        t91 = t9 * t14 * t90;
        t92 = t6 * 1.081543440204188E-16;
        t93 = t7 * 3.611241739452281E-17;
        t94 = t92 - t93 + 7.37474297704441E-1;
        t95 = t10 * t14 * t94;
        t96 = t91 + t95;
        t17 = fabs(t96);
        t18 = t7 * 1.76163991133662E-1;
        t98 = t6 * 9.482534011543849E-1;
        t19 = t18 - t98 + 1.466395492792771E-17;
        t20 = t6 * 1.76163991133662E-1;
        t21 = t7 * 9.482534011543849E-1;
        t22 = t20 + t21;
        t99 = t15 * t19;
        t100 = t16 * t22;
        t23 = t99 - t100;
        t24 = t9 * t14 * t23;
        t25 = t6 * 3.017878881450192E-18;
        t26 = t7 * 1.628054468477683E-16;
        t27 = t25 + t26 + 2.64162327796772E-1;
        t28 = t10 * t14 * t27;
        t29 = t24 + t28;
        t30 = fabs(t29);
        t52 = t6 * 1.296043728178216E-16;
        t53 = t7 * 2.63446951691103E-17;
        t54 = t52 + t53 - 6.21570530831645E-1;
        t55 = t10 * t14 * t54;
        t56 = t6 * 7.82867716781484E-1;
        t57 = t7 * 2.771665966547862E-2;
        t58 = t56 + t57;
        t59 = t16 * t58;
        t60 = t6 * 2.771665966547858E-2;
        t61 = t7 * 7.82867716781484E-1;
        t62 = t60 - t61 + 3.450409573788865E-17;
        t63 = t15 * t62;
        t64 = t59 + t63;
        t65 = t9 * t14 * t64;
        t66 = t55 - t65;
        t31 = fabs(t66);
        t32 = sin(t3);
        t33 = cos(t3);
        t34 = sin(A02);
        t35 = cos(A02);
        t105 = t4 * 1.734573094623198E-18;
        t106 = t5 * 5.55778172793303E-17;
        t107 = t105 - t106 + 1.31670187018151E-2;
        t108 = t32 * t107;
        t109 = t5 * 9.99913311051766E-1;
        t110 = t109 + 7.309163664212581E-19;
        t111 = t34 * t110;
        t112 = t4 * 9.99913311051766E-1;
        t113 = t5 * 2.24392928326991E-19;
        t114 = t112 - t113;
        t115 = t35 * t114;
        t116 = t111 - t115;
        t117 = t33 * t116;
        t118 = t108 + t117;
        t36 = fabs(t118);
        t37 = t4 * 3.648589206022503E-17;
        t38 = t5 * 5.858760529779916E-19;
        t39 = t37 + t38 - 7.545946601650509E-1;
        t40 = t32 * t39;
        t41 = t4 * 6.56115967162692E-1;
        t120 = t5 * 9.936623398114391E-3;
        t42 = t41 - t120 + 4.188841829872175E-17;
        t43 = t34 * t42;
        t44 = t4 * 9.936623398114391E-3;
        t45 = t5 * 6.56115967162692E-1;
        t46 = t44 + t45;
        t47 = t35 * t46;
        t48 = t43 + t47;
        t121 = t33 * t48;
        t49 = t40 - t121;
        t50 = fabs(t49);
        t67 = t4 * 7.54660080853734E-1;
        t68 = t5 * 8.639091210190649E-3;
        t69 = t67 + t68 - 3.641859531497865E-17;
        t70 = t34 * t69;
        t71 = t4 * 8.639091210190649E-3;
        t72 = t5 * 7.54660080853734E-1;
        t73 = t71 - t72;
        t74 = t35 * t73;
        t75 = t70 - t74;
        t76 = t33 * t75;
        t77 = t4 * 4.193100990166504E-17;
        t78 = t5 * 1.789310017978022E-18;
        t79 = t77 + t78 + 6.56059089159579E-1;
        t80 = t32 * t79;
        t81 = t76 - t80;
        t51 = fabs(t81);
        t97 = t17 * t17;
        t101 = t30 * t30;
        t102 = t31 * t31;
        t103 = t97 + t101 + t102;
        t104 = 1.0 / sqrt(t103);
        t119 = t36 * t36;
        t122 = t50 * t50;
        t123 = t51 * t51;
        t124 = t119 + t122 + t123;
        t125 = 1.0 / sqrt(t124);
        t126 = fabs(t29 * t49 * t104 * t125 - t66 * t81 * t104 * t125);
        t127 = fabs(t29 * t104 * t118 * t125 + t81 * t96 * t104 * t125);
        t128 = fabs(t49 * t96 * t104 * t125 + t66 * t104 * t118 * t125);
        t0 = sqrt(t126 * t126 + t127 * t127 + t128 * t128) - 1.745240643728351E-2;



        fi[2] = t0;

        //Definition de G3

        fi[3] = A11 - A1X_Max;

        //Définition de G4

        fi[4] = -A11 - A1X_Max;

        //Défintion de G5

        fi[5] = A13 - A1X_Max;

        //Définition de G6

        fi[6] = -A13 - A1X_Max;

        affiche_tableau(x);

    } 

public static double fabs(double a)
    {
        return (Math.Abs(a));
    }

    public static double cos(double a)
    {
        return (Math.Cos(a));
    }

    public static double sin(double a)
    {
        return (Math.Sin(a));
    }

    public static double sqrt(double a)
    {
        return (Math.Sqrt(a));
    }

    public static void affiche_tableau(double[] x)
    {
        string res = " ";
        for(int i=0;i<x.Length;i++)
        {
            res = res +" "+ ((int)((x[i]*100.0)))/100.0;
        }
        Console.WriteLine(res);
    }
4

1 回答 1

1

我已将 Michael JD Powell 教授的用于非线性优化的无导数算法移植到 C#。源代码在Github上可用,类库在 NuGet 上可用,名称为csnumerics

csnumerics包含用于不同约束应用的几种算法。对于非线性约束的问题,您应该选择COBYLA算法。

于 2017-06-05T12:32:04.580 回答