问:
How to solve a non linear constrained optimization in c#
I'd like to optimize a non linear fonction in c#, 12 or 15 variables (depending of the case). It is constrained by two non linear inequalities and 4 linear inequalities. I've tried the AUL (augmented lagragian) method with the ALGLIB repertory. Unfortunately, the algorithme converge towards the wrong minimum. I think it's because I can't think of an intial guess for a feasible solution.

Do anyone knows a way to solve this problem? Thanks a lot.

PS: I'm not an english speaker so, I'm sorry for the mistakes!

```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);
    }
```

答:
I have ported Prof. Michael JD Powell's derivative-free algorithms for nonlinear optimization to C#. The source code is available on Github and the class library is available on NuGet under the name csnumerics.

csnumerics contains several algorithms for different constraint applications. For problems with non-linear constraints, you should choose the COBYLA algorithm.

Body:
I'd like to optimize a non linear fonction in c#, 12 or 15 variables (depending of the case). It is constrained by two non linear inequalities and 4 linear inequalities. I've tried the AUL (augmented lagragian) method with the ALGLIB repertory. Unfortunately, the algorithme converge towards the wrong minimum. I think it's because I can't think of an intial guess for a feasible solution.

Do anyone knows a way to solve this problem? Thanks a lot.

PS: I'm not an english speaker so, I'm sorry for the mistakes!

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);
    }


来源: stackexchange

问:
how to create html table in php
I have the following snippet of code that basically uses explode to split out these values:

```<code><?php
$data=array();
$Inputfile = file("prod.txt");
foreach ($Inputfile as $line){
   $pieces = explode(";", $line);
   echo $pieces[0];
   echo $pieces[1];
   echo $pieces[2];
   echo $pieces[3];
//print_r($line);
}
?>
</code>```

Data: (prod.txt)

```<code>PREFIX=abc;PART=null;FILE=/myprojects/school/out/data/feed_abc_2010120810.gz2
PREFIX=efg;PART=sdsu;FILE=mail_efg.dat.2010120810.gz2
</code>```

Can someone show me how to put this in an HTML table dynamically, like this?? Is there an easy way to do this? Thanks.

```<code>PREFIX  PART   FILE
abc     null   /myprojects/school/out/data/feed_abc_2010120810.gz2
efg     sdsu   mail_efg.dat.2010120810.gz2
</code>```

答:
The Clean Way

```<code><?php
$inputfile = file("prod.txt");

$data_lines = array();
foreach ($inputfile as $line)
{
    $data_lines[] = explode(";", $line);
}

//Get column headers.
$first_line = array();
foreach ($data_lines[0] as $dl)
{
    $first_line[] = explode("=", $dl);
}
$headers = array();
foreach ($first_line as $fl)
{
    $headers[] = $fl[0];
}

// Get row content.
$data_cells = array();
for ($i = 0; $i < count($data_lines); $i++)
{
    $data_cell = array();
    for ($j = 0; $j < count($headers); $j++)
    {
        $data_cell[$j] = substr($data_lines[$i][$j], strpos($data_lines[$i][$j], "=")+1);
    }
    $data_cells[$i] = $data_cell;
    unset($data_cell);
}
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>HTML Table With PHP</title>
    </head>
    <body>
        <table border="1">
            <tr>
            <?php foreach ($headers as $header): ?>
                <th><?php echo $header; ?></th>
            <?php endforeach; ?>
            </tr>
        <?php foreach ($data_cells as $data_cell): ?>
            <tr>
            <?php for ($k = 0; $k < count($headers); $k++): ?>
                <td><?php echo $data_cell[$k]; ?></td>
            <?php endfor; ?>
            </tr>
        <?php endforeach; ?>
        </table>
    </body>
</html>
</code>```

ContentLicense: CC BY-SA 2.5

Title: how to create html table in php

Body:
I have the following snippet of code that basically uses explode to split out these values:

<?php
$data=array();
$Inputfile = file("prod.txt");
foreach ($Inputfile as $line){
   $pieces = explode(";", $line);
   echo $pieces[0];
   echo $pieces[1];
   echo $pieces[2];
   echo $pieces[3];
//print_r($line);
}
?>

Data: (prod.txt)

PREFIX=abc;PART=null;FILE=/myprojects/school/out/data/feed_abc_2010120810.gz2
PREFIX=efg;PART=sdsu;FILE=mail_efg.dat.2010120810.gz2

Can someone show me how to put this in an HTML table dynamically, like this?? Is there an easy way to do this? Thanks.

PREFIX  PART   FILE
abc     null   /myprojects/school/out/data/feed_abc_2010120810.gz2
efg     sdsu   mail_efg.dat.2010120810.gz2

Body:
The Clean Way

<?php
$inputfile = file("prod.txt");

$data_lines = array();
foreach ($inputfile as $line)
{
    $data_lines[] = explode(";", $line);
}

//Get column headers.
$first_line = array();
foreach ($data_lines[0] as $dl)
{
    $first_line[] = explode("=", $dl);
}
$headers = array();
foreach ($first_line as $fl)
{
    $headers[] = $fl[0];
}

// Get row content.
$data_cells = array();
for ($i = 0; $i < count($data_lines); $i++)
{
    $data_cell = array();
    for ($j = 0; $j < count($headers); $j++)
    {
        $data_cell[$j] = substr($data_lines[$i][$j], strpos($data_lines[$i][$j], "=")+1);
    }
    $data_cells[$i] = $data_cell;
    unset($data_cell);
}
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>HTML Table With PHP</title>
    </head>
    <body>
        <table border="1">
            <tr>
            <?php foreach ($headers as $header): ?>
                <th><?php echo $header; ?></th>
            <?php endforeach; ?>
            </tr>
        <?php foreach ($data_cells as $data_cell): ?>
            <tr>
            <?php for ($k = 0; $k < count($headers); $k++): ?>
                <td><?php echo $data_cell[$k]; ?></td>
            <?php endfor; ?>
            </tr>
        <?php endforeach; ?>
        </table>
    </body>
</html>


问:
Get excact Match array return
I want to get Match array and match should be excact Match in another array. </p>

```<code>  Array
    (
        [0] => चित्र
        [1] => माती
        [2] => त्यावर
        [3] => शेणाने
        [4] => सारवुन
        [5] => चित्र
        [6] => मातीार
        [7] => त्यावरार

    )

    Array
    (
        [0] => चित्र
        [1] => मातीती
        [2] => त्यावरती
        [3] => शेणानेती
        [4] => सारतीवुन
        [5] => चित्र
        [6] => मातीार
        [7] => त्यावरार

    )
</code>```

答:
```<code>$a1 =  array ( 'चित्र' ,'माती', 'त्यावर', 'शेणाने', 'सारवुन', 'चित्र',  'मातीार', 'त्यावरार');

$a2 = array('चित्र','मातीती','त्यावरती','शेणानेती','सारतीवुन','चित्र','मातीार','त्यावरार');

$match_array =  array_intersect($a1, $a2);

print_r($match_array);
</code>```

ContentLicense: CC BY-SA 3.0

Title: Get excact Match array return

Body:
I want to get Match array and match should be excact Match in another array.

  Array
    (
        [0] => चित्र
        [1] => माती
        [2] => त्यावर
        [3] => शेणाने
        [4] => सारवुन
        [5] => चित्र
        [6] => मातीार
        [7] => त्यावरार

    )

    Array
    (
        [0] => चित्र
        [1] => मातीती
        [2] => त्यावरती
        [3] => शेणानेती
        [4] => सारतीवुन
        [5] => चित्र
        [6] => मातीार
        [7] => त्यावरार

    )


问:
Count keywords occurrence in a file to another file
I have two files File1 and File2. I have to find keywords in File2 to File1 and count it. Lines in File1 that don't have any keywords in File2 shall be counted as OTHERS and probably save it in File3 (for validation).

File1

```<code> 000001111YYYY0000
 122334YYYY9999
 89898989AAAA89899
 AAAA7678989812234
 ZZZZ878098098098
 0000000000000000
</code>```

File2

```<code>YYYY
AAAA
ZZZZ
</code>```

Output

```<code>YYYY: 2
AAAA: 2
ZZZZ: 1
OTHERS: 1
</code>```

File3 (OTHERS)

```<code>0000000000000000
</code>```

The way I know is to count the keywords using grep and wc -l, and its not ideal especially when I have many keywords to find.

答:
Using awk

CMDLINE

```<code>awk 'FNR==NR{a[$1];next}\
{b=1;for(i in a)if(z=gsub(i,"&")){x[i]+=z;b=0}}\
b{x["Others"]++;print > "file3"}\
END{for(i in x)print i, x[i]}' file{2,}
</code>```

Or probably more suited to a script due to length

```<code>FNR==NR{
    Strings[$1]
    next
}
{
    Found=0
    for(Regex in Strings)
        if(matches=gsub(Regex,"&")){
            Sums[Regex]+=matches
            Found=1
        }
}
!Found{
    Sums["Others"]++
    print > "file3"
}
END{
     for(Regex in Sums)
         print Regex, Sums[Regex]
}
</code>```

Save as

```<code>awkscript.awk
</code>```

Run as

```<code>awk -f awkscript.awk file{2,}
</code>```

Body:
I have two files File1 and File2. I have to find keywords in File2 to File1 and count it. Lines in File1 that don't have any keywords in File2 shall be counted as OTHERS and probably save it in File3 (for validation).

File1

 000001111YYYY0000
 122334YYYY9999
 89898989AAAA89899
 AAAA7678989812234
 ZZZZ878098098098
 0000000000000000

File2

YYYY
AAAA
ZZZZ

Output

YYYY: 2
AAAA: 2
ZZZZ: 1
OTHERS: 1

File3 (OTHERS)

0000000000000000

The way I know is to count the keywords using grep and wc -l, and its not ideal especially when I have many keywords to find.

Body:
Using awk

CMDLINE

awk 'FNR==NR{a[$1];next}\
{b=1;for(i in a)if(z=gsub(i,"&")){x[i]+=z;b=0}}\
b{x["Others"]++;print > "file3"}\
END{for(i in x)print i, x[i]}' file{2,}

Or probably more suited to a script due to length

FNR==NR{
    Strings[$1]
    next
}
{
    Found=0
    for(Regex in Strings)
        if(matches=gsub(Regex,"&")){
            Sums[Regex]+=matches
            Found=1
        }
}
!Found{
    Sums["Others"]++
    print > "file3"
}
END{
     for(Regex in Sums)
         print Regex, Sums[Regex]
}

Save as

awkscript.awk

Run as

awk -f awkscript.awk file{2,}


问:
Running PL/SQL script in PHP
I have a script in PL/SQL , that drop some tables , sequences , triggers, and creating them again in the same script , I need this script in my website for deleting all data from database (and I want to acces this script pressing one button on website) so I tried to do a function / procedure in PL/SQL that read line by line from the script file and executing every line with dynamic sql , everything went ok till one error at:

CREATE OR REPLACE TRIGGER players_bir BEFORE INSERT ON players FOR EACH ROW BEGIN SELECT players_seq.NEXTVAL INTO :new.id FROM dual END

this gave me the error:

ORA-24344: success with compilation error

I searched for solutions, but I didn't find anything.

答:
You are missing the semi-colon after dual on your SELECT statement.  This ORA error generally means you compiled some code, but that is has some issue.

```<code>CREATE OR REPLACE TRIGGER players_bir
  BEFORE INSERT ON players
  FOR EACH ROW
BEGIN
  SELECT players_seq.nextval
    INTO :new.id
    FROM dual;
END
</code>```

Looking in all_errors will show you what the issue is or you could manually compile this trigger in some IDE (like SQL Developer) and that should also make it obvious.

```<code>SELECT *
  FROM all_errors e
 WHERE e.name = 'PLAYERS_BIR'
   AND e.type = 'TRIGGER';
</code>```

Additionally if all you are using your trigger for is to set some identity column and you are on Oracle 12c you can use some of the new features to accomplish this.  Triggers are inherently slow and the new identity feature performs about as good as referencing the sequence directly in your INSERT.

Title: Running PL/SQL script in PHP

Body:
You are missing the semi-colon after dual on your SELECT statement.  This ORA error generally means you compiled some code, but that is has some issue.

CREATE OR REPLACE TRIGGER players_bir
  BEFORE INSERT ON players
  FOR EACH ROW
BEGIN
  SELECT players_seq.nextval
    INTO :new.id
    FROM dual;
END

Looking in all_errors will show you what the issue is or you could manually compile this trigger in some IDE (like SQL Developer) and that should also make it obvious.

SELECT *
  FROM all_errors e
 WHERE e.name = 'PLAYERS_BIR'
   AND e.type = 'TRIGGER';

Additionally if all you are using your trigger for is to set some identity column and you are on Oracle 12c you can use some of the new features to accomplish this.  Triggers are inherently slow and the new identity feature performs about as good as referencing the sequence directly in your INSERT.


问:
Injection of autowired dependencies failed inside a jar file
I have put a jar file under lib folder of my war file. Inside the jar I have some classes with  @Autowired fileds. Inside the jar , in the applicationContext xml I have given

```<code><context:component-scan base-package="com.main.java.mypath" />
</code>```

Code:

```<code>package com.main.java.mypath.client;

@Component
public class ServiceProvider {

   @Autowired
   private StoreField storeField;

package com.main.java.mypath.data;
public interface StoreField {
}
</code>```

Error:

```<code>org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'serviceProvider': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private com.main.java.mypath.data.StoreField com.main.java.mypath.client.ServiceProvider.storeField; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [com.main.java.mypath.data.StoreField] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}
</code>```

答: It is not possible to inject the dependency as long as you don't have the implementation for your StoreField interface. Make sure that it is implemented as a class and properly initialized in spring context via xml or annotation.

Body:
I have put a jar file under lib folder of my war file. Inside the jar I have some classes with  @Autowired fileds. Inside the jar , in the applicationContext xml I have given

<context:component-scan base-package="com.main.java.mypath" />

Code:

package com.main.java.mypath.client;

@Component
public class ServiceProvider {

   @Autowired
   private StoreField storeField;

package com.main.java.mypath.data;
public interface StoreField {
}

Error:

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'serviceProvider': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private com.main.java.mypath.data.StoreField com.main.java.mypath.client.ServiceProvider.storeField; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [com.main.java.mypath.data.StoreField] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}


问:
Determine language in functions.php [wpml]
I have function in functions.php , which automatically adds woocommerce product by ID to cart when website is visited.

The website is bilingual and the function can't determine translated product ID.

So, I want to know if is possible to add wpml function in functions.php, which determines first language of front end, then executes function, something like this:

```<code><?php if(wpml_getLanguage()=='en'); ?>
---do function for product 22---
<?php elseif(wpml_getLanguage()=='it'); ?>
---do function for product 45--
<?php endif; ?>
</code>```

My code:

```<code>add_action( 'template_redirect', 'add_product_to_cart' );
function add_product_to_cart() {
    if ( ! is_admin() ) {
        $product_id = 22;
        $found = false;
        //check if product already in cart
        if ( sizeof( WC()->cart->get_cart() ) > 0 ) {
            foreach ( WC()->cart->get_cart() as $cart_item_key => $values ) {
                $_product = $values['data'];
                if ( $_product->id == $product_id )
                    $found = true;
            }
            // if product not found, add it
            if ( ! $found )
                WC()->cart->add_to_cart( $product_id );
        } else {
            // if no products in cart, add it
            WC()->cart->add_to_cart( $product_id );
        }
    }
}
</code>```

答:
This can be dropped into functions.php</p>

```<code>add_action( 'init', 'add_product_on_language' );

function add_product_on_language(){
    if ( ! is_admin() ) {

        if( ICL_LANGUAGE_CODE == 'en' ){
            $product_id = 22;
        } elseif ( ICL_LANGUAGE_CODE == 'it' ) {
            $product_id = 45;
        }

        $found = false;
        //check if product already in cart
        if ( sizeof( WC()->cart->get_cart() ) > 0 ) {
            foreach ( WC()->cart->get_cart() as $cart_item_key => $values ) {
                $_product = $values['data'];
                if ( $_product->id == $product_id )
                    $found = true;
            }
            // if product not found, add it
            if ( ! $found )
                WC()->cart->add_to_cart( $product_id );
        } else {
            // if no products in cart, add it
            WC()->cart->add_to_cart( $product_id );
        }
    }
}
</code>```

Body:
I have function in functions.php , which automatically adds woocommerce product by ID to cart when website is visited.

The website is bilingual and the function can't determine translated product ID.

So, I want to know if is possible to add wpml function in functions.php, which determines first language of front end, then executes function, something like this:

<?php if(wpml_getLanguage()=='en'); ?>
---do function for product 22---
<?php elseif(wpml_getLanguage()=='it'); ?>
---do function for product 45--
<?php endif; ?>

My code:

add_action( 'template_redirect', 'add_product_to_cart' );
function add_product_to_cart() {
    if ( ! is_admin() ) {
        $product_id = 22;
        $found = false;
        //check if product already in cart
        if ( sizeof( WC()->cart->get_cart() ) > 0 ) {
            foreach ( WC()->cart->get_cart() as $cart_item_key => $values ) {
                $_product = $values['data'];
                if ( $_product->id == $product_id )
                    $found = true;
            }
            // if product not found, add it
            if ( ! $found )
                WC()->cart->add_to_cart( $product_id );
        } else {
            // if no products in cart, add it
            WC()->cart->add_to_cart( $product_id );
        }
    }
}

Body:
This can be dropped into functions.php

add_action( 'init', 'add_product_on_language' );

function add_product_on_language(){
    if ( ! is_admin() ) {

        if( ICL_LANGUAGE_CODE == 'en' ){
            $product_id = 22;
        } elseif ( ICL_LANGUAGE_CODE == 'it' ) {
            $product_id = 45;
        }

        $found = false;
        //check if product already in cart
        if ( sizeof( WC()->cart->get_cart() ) > 0 ) {
            foreach ( WC()->cart->get_cart() as $cart_item_key => $values ) {
                $_product = $values['data'];
                if ( $_product->id == $product_id )
                    $found = true;
            }
            // if product not found, add it
            if ( ! $found )
                WC()->cart->add_to_cart( $product_id );
        } else {
            // if no products in cart, add it
            WC()->cart->add_to_cart( $product_id );
        }
    }
}


问:
Why jenkins can not perform certain names of jmx?
1.It can't perform when my script name is lotteryOnline:

2.But changed to other names (such as game), BUILD SUCCESSFUL：

答: Because there is a file, which is called game.itl. The parameter where you supply game is used to pick that file, as it seems.


问:
C# Call function from another form (radform)
First of all, I would like to point out that I have searched for a solution to this problem without luck.

So basicly I have a Mysql function in Radform1 witch I want to call from CustomAppointmentEditForm

Radform1

```<code>  public RadForm1()
    {
        InitializeComponent();

    }
</code>```

CustomAppointmentEditForm

```<code>        public CustomAppointmentEditForm()
    {
        InitializeComponent();

    }
</code>```

The function I want to call from Radform1

```<code>private void Update_LeadInfo()
    {
        try
        {
            using (MySqlConnection cn = new MySqlConnection(ConString))
            {
                string UniqueID = textBoxDescription.Text;

                string CVR = txtCVR.Text;
                string Firma = txtFirma.Text;
                string Nummer = txtNummer.Text;
                string Addresse = txtAddresse.Text;
                string Postnr = txtPostnr.Text;
                string By = txtBy.Text;
                string Noter = txtNoter.Text;
                string Email = txtEmail.Text;
                string StartDato = dateStart.Text + " " + timeStart.Text;
                string SlutDato = dateEnd.Text + " " + timeEnd.Text;
                string Afholdt = radCheckBox1.CheckState.ToString();
                if(Afholdt == "Checked")
                {
                    Afholdt = "1";
                }
                else
                {
                    Afholdt = "0";
                }
                if(chkAllDay.CheckState == CheckState.Checked)
                {
                    StartDato = dateStart.Text + " " + "00:00";
                    SlutDato = dateEnd.Text + " " + "00:00";
                }
                cn.Open();

                Console.WriteLine(UniqueID);
                MySqlCommand cmd = new MySqlCommand();
                cmd.Connection = cn;
                cmd.CommandText = "UPDATE Leads SET CVR = ('" + CVR + "'), Firma = ('" + Firma + "'), Nummer = ('" + Nummer + "'), Addresse = ('" + Addresse + "'), Postnr = ('" + Postnr + "'), Bynavn = ('" + By + "'), Noter = ('" + Noter + "'), Afholdt = ('" + Afholdt + "'), Email = ('" + Email + "'), Slut_Dato = ('" + SlutDato + "')  WHERE UniqueID = ('" + UniqueID + "');";
                cmd.ExecuteNonQuery();

                cmd.Dispose();
                cn.Close();
            }
        }
        catch (Exception Fejl)
        {
            Console.WriteLine(Fejl);
        }
    }
</code>```

I know there is a simple solution to this, thanks in advance

答:
Firstly, Update_LeadInfo() seems like business logic, and you should not have business-logic in UI layer. If you move it to separate data access project, you can refactor your code like that:

DataAccessLayer:

```<code>class DataAdapter
{
    public void UpdateLeads(LeadsInfo info)
    {
        using (MySqlConnection cn = new MySqlConnection(ConString))
        {
            cn.Open();

            MySqlCommand cmd = new MySqlCommand();
            cmd.Connection = cn;
            cmd.CommandText = "UPDATE Leads SET CVR = ('" + info.CVR + "'), Firma = ('" + info.Firma + "')," /* ... */;
            cmd.ExecuteNonQuery();

            cmd.Dispose();
            cn.Close();
        }
    }
}
</code>```

UI Layer:

```<code>class RadForm1
{
    public RadForm1(DataAdapter adapter)
    {
        if (adapter == null)
            throw new ArgumentNullException("adapter");

        InitializeComponent();
        this.Adapter = adapter
    }

    private void Update_LeadInfo()
    {
        this.Adapter.UpdateLeads(new LeadsInfo(
                          CVR: txtCVR.Text,
                          Firma: txtFirma.Text,
                          /* ... */));
    }
}

class CustomAppointmentForm
{
    public CustomAppointmentForm(DataAdapter adapter)
    {
        if (adapter == null)
            throw new ArgumentNullException("adapter");

        InitializeComponent();
        this.Adapter = adapter
    }

    private void Update_LeadInfo()
    {
        this.Adapter.UpdateLeads(new LeadsInfo(
                          CVR: txtCVR.Text,
                          Firma: txtFirma.Text,
                          /* ... */));
    }
}
</code>```

Body:
First of all, I would like to point out that I have searched for a solution to this problem without luck.

So basicly I have a Mysql function in Radform1 witch I want to call from CustomAppointmentEditForm

Radform1

  public RadForm1()
    {
        InitializeComponent();

    }

CustomAppointmentEditForm

        public CustomAppointmentEditForm()
    {
        InitializeComponent();

    }

The function I want to call from Radform1

private void Update_LeadInfo()
    {
        try
        {
            using (MySqlConnection cn = new MySqlConnection(ConString))
            {
                string UniqueID = textBoxDescription.Text;

                string CVR = txtCVR.Text;
                string Firma = txtFirma.Text;
                string Nummer = txtNummer.Text;
                string Addresse = txtAddresse.Text;
                string Postnr = txtPostnr.Text;
                string By = txtBy.Text;
                string Noter = txtNoter.Text;
                string Email = txtEmail.Text;
                string StartDato = dateStart.Text + " " + timeStart.Text;
                string SlutDato = dateEnd.Text + " " + timeEnd.Text;
                string Afholdt = radCheckBox1.CheckState.ToString();
                if(Afholdt == "Checked")
                {
                    Afholdt = "1";
                }
                else
                {
                    Afholdt = "0";
                }
                if(chkAllDay.CheckState == CheckState.Checked)
                {
                    StartDato = dateStart.Text + " " + "00:00";
                    SlutDato = dateEnd.Text + " " + "00:00";
                }
                cn.Open();

                Console.WriteLine(UniqueID);
                MySqlCommand cmd = new MySqlCommand();
                cmd.Connection = cn;
                cmd.CommandText = "UPDATE Leads SET CVR = ('" + CVR + "'), Firma = ('" + Firma + "'), Nummer = ('" + Nummer + "'), Addresse = ('" + Addresse + "'), Postnr = ('" + Postnr + "'), Bynavn = ('" + By + "'), Noter = ('" + Noter + "'), Afholdt = ('" + Afholdt + "'), Email = ('" + Email + "'), Slut_Dato = ('" + SlutDato + "')  WHERE UniqueID = ('" + UniqueID + "');";
                cmd.ExecuteNonQuery();

                cmd.Dispose();
                cn.Close();
            }
        }
        catch (Exception Fejl)
        {
            Console.WriteLine(Fejl);
        }
    }

I know there is a simple solution to this, thanks in advance

Body:
Firstly, Update_LeadInfo() seems like business logic, and you should not have business-logic in UI layer. If you move it to separate data access project, you can refactor your code like that:

DataAccessLayer:

class DataAdapter
{
    public void UpdateLeads(LeadsInfo info)
    {
        using (MySqlConnection cn = new MySqlConnection(ConString))
        {
            cn.Open();

            MySqlCommand cmd = new MySqlCommand();
            cmd.Connection = cn;
            cmd.CommandText = "UPDATE Leads SET CVR = ('" + info.CVR + "'), Firma = ('" + info.Firma + "')," /* ... */;
            cmd.ExecuteNonQuery();

            cmd.Dispose();
            cn.Close();
        }
    }
}

UI Layer:

class RadForm1
{
    public RadForm1(DataAdapter adapter)
    {
        if (adapter == null)
            throw new ArgumentNullException("adapter");

        InitializeComponent();
        this.Adapter = adapter
    }

    private void Update_LeadInfo()
    {
        this.Adapter.UpdateLeads(new LeadsInfo(
                          CVR: txtCVR.Text,
                          Firma: txtFirma.Text,
                          /* ... */));
    }
}

class CustomAppointmentForm
{
    public CustomAppointmentForm(DataAdapter adapter)
    {
        if (adapter == null)
            throw new ArgumentNullException("adapter");

        InitializeComponent();
        this.Adapter = adapter
    }

    private void Update_LeadInfo()
    {
        this.Adapter.UpdateLeads(new LeadsInfo(
                          CVR: txtCVR.Text,
                          Firma: txtFirma.Text,
                          /* ... */));
    }
}


问:
replace NAs in a column of a data.table with means of the same column grouped by a factor
I have the following sample data table

```<code>steps.dt = data.table(steps=rep(0:2, each=3),
date=as.factor(rep(c("10/2/2012", "10/3/2012", "10/4/2012"), each = 3)), interval = as.factor(rep(c(0,5,10), each = 3)))
</code>```

inserting a few NAs

```<code>steps.dt[c(2,5,8),"steps"]=NA
</code>```

the table now looks like this

```<code>   steps      date interval
1:     0 10/2/2012        0
2:    NA 10/2/2012        0
3:     0 10/2/2012        0
4:     1 10/3/2012        5
5:    NA 10/3/2012        5
6:     1 10/3/2012        5
7:     2 10/4/2012       10
8:    NA 10/4/2012       10
9:     2 10/4/2012       10
</code>```

Now, I am trying to replace the NAs in the column "steps" with the means of steps grouped by the factor "interval"

I have looked at some of the posts on SO like this but that I need the replacement to be grouped by a factor is complicating it. Is there a way to do this without using a loop? thank you!

答:
We can use na.aggregate from zoo to replace the 'NA' with the mean of the 'steps' after grouping by 'interval'

```<code>library(zoo)
steps.dt[, steps := na.aggregate(steps), interval]
</code>```

Body:
I have the following sample data table

steps.dt = data.table(steps=rep(0:2, each=3),
date=as.factor(rep(c("10/2/2012", "10/3/2012", "10/4/2012"), each = 3)), interval = as.factor(rep(c(0,5,10), each = 3)))

inserting a few NAs

steps.dt[c(2,5,8),"steps"]=NA

the table now looks like this

   steps      date interval
1:     0 10/2/2012        0
2:    NA 10/2/2012        0
3:     0 10/2/2012        0
4:     1 10/3/2012        5
5:    NA 10/3/2012        5
6:     1 10/3/2012        5
7:     2 10/4/2012       10
8:    NA 10/4/2012       10
9:     2 10/4/2012       10

Now, I am trying to replace the NAs in the column "steps" with the means of steps grouped by the factor "interval"

I have looked at some of the posts on SO like this but that I need the replacement to be grouped by a factor is complicating it. Is there a way to do this without using a loop? thank you!

Body:
We can use na.aggregate from zoo to replace the 'NA' with the mean of the 'steps' after grouping by 'interval'

library(zoo)
steps.dt[, steps := na.aggregate(steps), interval]


问:
How am I able to move my
 to where I want it?
How can I move my menu
 to the bottom left in this div?

Codepen: https://codepen.io/audn/pen/QgwvNq

I've tried margin-left:auto, but didn't seem to work.
Is it because of my padding?

HTML:

.verified{
  font-size:5px;
}
ul.media {
  list-style-type: none;
  margin: 0;
  padding: 0;
  overflow: hidden;
  margin-left: auto;
  background-color: #111019;
}
li.media {
  float: left;
}
li.media a {
  display: block;
  color: white;
  text-align: center;
  padding: 14px 16px;
  text-decoration: none;
}
li.media a:hover {
  background-color: #111019;
}
.content-selfmade{
  width: 250px;
  background-color: #111019;
  padding: 15px 15px;
  float:left;
  color: white;
  margin-left: auto;
  margin-right: auto;
  border-radius: .2em;
  margin-bottom: 10px;
  margin-left: 10px;
  height: 120px;
}
.tooltip {
  position: relative;
  display: inline-block;
  border-bottom: 1px dotted black;
}
.staff-verified{
  color: #e58900;
}
.lightPill{
  color:white;
  background-color:#e58900;
  padding:.1em .35em;
  border-radius:1px;
  font-size:.75em;
}
.tooltip .tooltiptext {
  visibility: hidden;
  width: 120px;
  background-color: black;
  color: #fff;
  text-align: center;
  border-radius: 6px;
  padding: 5px 0;
  /* Position the tooltip */
  position: absolute;
  z-index: 1;
}
.btn-team {
  border: 1px solid #e58900;
  border-radius: 5px;
  font-family: Arial;
  float:left;
  margin-top: 10px;
  color: #ffffff;
  font-size: 12px;
  padding: 5px 15px 5px 15px;
  text-decoration: none;
}

.btn-team:hover {
  cursor: pointer;
  border: 1px solid #7c4b01;
  text-decoration: none;
  float:left;
}

.tooltip:hover .tooltiptext {
  visibility: visible;
}
.h2{
  font-size: 11px;
}
#steam-photo{
  background-image: url('http://i.imgur.com/fkue1Ww.png');
  border-radius: 50%;
  width: 75px;
  height: 75px;
}
#team-members{
  width: 25px;
  height:25px;
  border-radius: 50%;
  float:left;
  margin-left: 5px;
  margin-top: 5px;
}
.content-selfmade-name{
  top: 0;
  display: block;
  font-size:  1rem;
  float: right;
  width: 140px;
  margin-top: 10px;
}```
<pre class="snippet-code-html lang-html prettyprint-override"><code> <div class="content-selfmade">
    <img id="steam-photo" src="http://i.imgur.com/fkue1Ww.png"></span>
    <span class="content-selfmade-name">Audn
      <font style="color:#0288D1;";>

          <div class="tooltip">
            <i class="fa fa-check-circle" aria-hidden="true"></i>
              <span class="tooltiptext">Verified Staff member.</span>
          </div>

      </font>
      <div class="h2">
        <span class="staff-verified">PUBG.team developer.</span>
      </div>
    <img id="team-members" src="https://cdn.discordapp.com/attachments/301429296390602752/321126144193593345/yggdrasil128.png">
    <img id="team-members" src="http://i.imgur.com/9Ix1SKa.jpg">
    <img id="team-members" src="http://i.imgur.com/RsOTLvl.png">
    <p>
  </span>
  <ul class="media">
    <li class="media">Stats</li>
    <li class="media">Steam</li>
  </ul>
</div></code>```

答:
There is a
 tag in your code that is not closed properly.Remove that or close that.then the ul will align correctly

.verified{
  font-size:5px;
}
ul.media {
  list-style-type: none;
  margin: 0;
  padding: 0;
  overflow: hidden;
  margin-left: auto;
  background-color: #111019;
}
li.media {
  float: left;
}
li.media a {
  display: block;
  color: white;
  text-align: center;
  padding: 14px 16px;
  text-decoration: none;
}
li.media a:hover {
  background-color: #111019;
}
.content-selfmade{
  width: 250px;
  background-color: #111019;
  padding: 15px 15px;
  float:left;
  color: white;
  margin-left: auto;
  margin-right: auto;
  border-radius: .2em;
  margin-bottom: 10px;
  margin-left: 10px;
  height: 120px;
}
.tooltip {
  position: relative;
  display: inline-block;
  border-bottom: 1px dotted black;
}
.staff-verified{
  color: #e58900;
}
.lightPill{
  color:white;
  background-color:#e58900;
  padding:.1em .35em;
  border-radius:1px;
  font-size:.75em;
}
.tooltip .tooltiptext {
  visibility: hidden;
  width: 120px;
  background-color: black;
  color: #fff;
  text-align: center;
  border-radius: 6px;
  padding: 5px 0;
  /* Position the tooltip */
  position: absolute;
  z-index: 1;
}
.btn-team {
  border: 1px solid #e58900;
  border-radius: 5px;
  font-family: Arial;
  float:left;
  margin-top: 10px;
  color: #ffffff;
  font-size: 12px;
  padding: 5px 15px 5px 15px;
  text-decoration: none;
}

.btn-team:hover {
  cursor: pointer;
  border: 1px solid #7c4b01;
  text-decoration: none;
  float:left;
}

.tooltip:hover .tooltiptext {
  visibility: visible;
}
.h2{
  font-size: 11px;
}
#steam-photo{
  background-image: url('http://i.imgur.com/fkue1Ww.png');
  border-radius: 50%;
  width: 75px;
  height: 75px;
}
#team-members{
  width: 25px;
  height:25px;
  border-radius: 50%;
  float:left;
  margin-left: 5px;
  margin-top: 5px;
}
.content-selfmade-name{
  top: 0;
  display: block;
  font-size:  1rem;
  float: right;
  width: 140px;
  margin-top: 10px;
}```
<pre class="snippet-code-html lang-html prettyprint-override"><code> <div class="content-selfmade">
    <img id="steam-photo" src="http://i.imgur.com/fkue1Ww.png"></span>
    <span class="content-selfmade-name">Audn
      <font style="color:#0288D1;";>

          <div class="tooltip">
            <i class="fa fa-check-circle" aria-hidden="true"></i>
              <span class="tooltiptext">Verified Staff member.</span>
          </div>

      </font>
      <div class="h2">
        <span class="staff-verified">PUBG.team developer.</span>
      </div>
    <img id="team-members" src="https://cdn.discordapp.com/attachments/301429296390602752/321126144193593345/yggdrasil128.png">
    <img id="team-members" src="http://i.imgur.com/9Ix1SKa.jpg">
    <img id="team-members" src="http://i.imgur.com/RsOTLvl.png">
    <p></p>
  </span>
  <ul class="media">
    <li class="media">Stats</li>
    <li class="media">Steam</li>
  </ul>
</div></code>```

https://codepen.io/anon/pen/awzWqg

Title: How am I able to move my <ul> to where I want it?

Body:
How can I move my menu
 to the bottom left in this div?

Codepen: https://codepen.io/audn/pen/QgwvNq

I've tried margin-left:auto, but didn't seem to work.
Is it because of my padding?

HTML:

.verified{
  font-size:5px;
}
ul.media {
  list-style-type: none;
  margin: 0;
  padding: 0;
  overflow: hidden;
  margin-left: auto;
  background-color: #111019;
}
li.media {
  float: left;
}
li.media a {
  display: block;
  color: white;
  text-align: center;
  padding: 14px 16px;
  text-decoration: none;
}
li.media a:hover {
  background-color: #111019;
}
.content-selfmade{
  width: 250px;
  background-color: #111019;
  padding: 15px 15px;
  float:left;
  color: white;
  margin-left: auto;
  margin-right: auto;
  border-radius: .2em;
  margin-bottom: 10px;
  margin-left: 10px;
  height: 120px;
}
.tooltip {
  position: relative;
  display: inline-block;
  border-bottom: 1px dotted black;
}
.staff-verified{
  color: #e58900;
}
.lightPill{
  color:white;
  background-color:#e58900;
  padding:.1em .35em;
  border-radius:1px;
  font-size:.75em;
}
.tooltip .tooltiptext {
  visibility: hidden;
  width: 120px;
  background-color: black;
  color: #fff;
  text-align: center;
  border-radius: 6px;
  padding: 5px 0;
  /* Position the tooltip */
  position: absolute;
  z-index: 1;
}
.btn-team {
  border: 1px solid #e58900;
  border-radius: 5px;
  font-family: Arial;
  float:left;
  margin-top: 10px;
  color: #ffffff;
  font-size: 12px;
  padding: 5px 15px 5px 15px;
  text-decoration: none;
}

.btn-team:hover {
  cursor: pointer;
  border: 1px solid #7c4b01;
  text-decoration: none;
  float:left;
}

.tooltip:hover .tooltiptext {
  visibility: visible;
}
.h2{
  font-size: 11px;
}
#steam-photo{
  background-image: url('http://i.imgur.com/fkue1Ww.png');
  border-radius: 50%;
  width: 75px;
  height: 75px;
}
#team-members{
  width: 25px;
  height:25px;
  border-radius: 50%;
  float:left;
  margin-left: 5px;
  margin-top: 5px;
}
.content-selfmade-name{
  top: 0;
  display: block;
  font-size:  1rem;
  float: right;
  width: 140px;
  margin-top: 10px;
}

    Audn

              Verified Staff member.

        PUBG.team developer.

Stats

Steam

Body:
There is a  <p> tag in your code that is not closed properly.Remove that or close that.then the ul will align correctly

.verified{
  font-size:5px;
}
ul.media {
  list-style-type: none;
  margin: 0;
  padding: 0;
  overflow: hidden;
  margin-left: auto;
  background-color: #111019;
}
li.media {
  float: left;
}
li.media a {
  display: block;
  color: white;
  text-align: center;
  padding: 14px 16px;
  text-decoration: none;
}
li.media a:hover {
  background-color: #111019;
}
.content-selfmade{
  width: 250px;
  background-color: #111019;
  padding: 15px 15px;
  float:left;
  color: white;
  margin-left: auto;
  margin-right: auto;
  border-radius: .2em;
  margin-bottom: 10px;
  margin-left: 10px;
  height: 120px;
}
.tooltip {
  position: relative;
  display: inline-block;
  border-bottom: 1px dotted black;
}
.staff-verified{
  color: #e58900;
}
.lightPill{
  color:white;
  background-color:#e58900;
  padding:.1em .35em;
  border-radius:1px;
  font-size:.75em;
}
.tooltip .tooltiptext {
  visibility: hidden;
  width: 120px;
  background-color: black;
  color: #fff;
  text-align: center;
  border-radius: 6px;
  padding: 5px 0;
  /* Position the tooltip */
  position: absolute;
  z-index: 1;
}
.btn-team {
  border: 1px solid #e58900;
  border-radius: 5px;
  font-family: Arial;
  float:left;
  margin-top: 10px;
  color: #ffffff;
  font-size: 12px;
  padding: 5px 15px 5px 15px;
  text-decoration: none;
}

.btn-team:hover {
  cursor: pointer;
  border: 1px solid #7c4b01;
  text-decoration: none;
  float:left;
}

.tooltip:hover .tooltiptext {
  visibility: visible;
}
.h2{
  font-size: 11px;
}
#steam-photo{
  background-image: url('http://i.imgur.com/fkue1Ww.png');
  border-radius: 50%;
  width: 75px;
  height: 75px;
}
#team-members{
  width: 25px;
  height:25px;
  border-radius: 50%;
  float:left;
  margin-left: 5px;
  margin-top: 5px;
}
.content-selfmade-name{
  top: 0;
  display: block;
  font-size:  1rem;
  float: right;
  width: 140px;
  margin-top: 10px;
}

 <div class="content-selfmade">
    <img id="steam-photo" src="http://i.imgur.com/fkue1Ww.png"></span>
    <span class="content-selfmade-name">Audn
      <font style="color:#0288D1;";>
        <a href="/verified">
          <div class="tooltip">
            <i class="fa fa-check-circle" aria-hidden="true"></i>
              <span class="tooltiptext">Verified Staff member.</span>
          </div>
        </a>
      </font>
      <div class="h2">
        <span class="staff-verified">PUBG.team developer.</span>
      </div>
    <img id="team-members" src="https://cdn.discordapp.com/attachments/301429296390602752/321126144193593345/yggdrasil128.png">
    <img id="team-members" src="http://i.imgur.com/9Ix1SKa.jpg">
    <img id="team-members" src="http://i.imgur.com/RsOTLvl.png">
    <p></p>
  </span>
  <ul class="media">
    <li class="media"><a href="#index">Stats</a></li>
    <li class="media"><a href="#index">Steam</a></li>
  </ul>
</div>

https://codepen.io/anon/pen/awzWqg


问:
Populate Enumerable.ToList with one line of code
Please see the person class below:

```<code>public class Person
    {
        int _id { get; set; }
        string _name { get; set; }

        public Person (int id, string name)
        {
            _id = id;
            _name = name;
        }

        public Person()
        {
        }

        public IEnumerable<Person> GetPeople()
        {
            _id = 1;
            _name = "James";
            yield return this;

            _id = 2;
            _name = "Michael";
            yield return this;

            _id = 3;
            _name = "Sarah";
            yield return this;
        }
    }
</code>```

and the client code below:

```<code>Person p1 = new Person();
IEnumerable<Person> personEnumerable = p1.GetPeople();
List<Person> personList = personEnumerable.ToList();
</code>```

Why does PersonList contain three entries for Sarah after this has run? What is the best way to populate personList in the client?

答:
You should probably have seen this behaviour, right?

```<code>var p1 = new Person(1, "Tom");
var p2 = p1;
p2._id = 2;
// now p1._id is 2 as well!
</code>```

This is exactly what is happening here. After the first return this, this is modified again with id 2 and name Michael. This causes the returned this to change as well, because they refer to the same object. You never created a new object using new. The same thing happens with the third yield return.

To fix this, simply change Person to a struct (so it's now a value type), or implement the method like JanDotNet did in his answer.

Body:
Please see the person class below:

public class Person
    {
        int _id { get; set; }
        string _name { get; set; }

        public Person (int id, string name)
        {
            _id = id;
            _name = name;
        }

        public Person()
        {
        }

        public IEnumerable<Person> GetPeople()
        {
            _id = 1;
            _name = "James";
            yield return this;

            _id = 2;
            _name = "Michael";
            yield return this;

            _id = 3;
            _name = "Sarah";
            yield return this;
        }
    }

and the client code below:

Person p1 = new Person();
IEnumerable<Person> personEnumerable = p1.GetPeople();
List<Person> personList = personEnumerable.ToList();

Why does PersonList contain three entries for Sarah after this has run? What is the best way to populate personList in the client?

Body:
You should probably have seen this behaviour, right?

var p1 = new Person(1, "Tom");
var p2 = p1;
p2._id = 2;
// now p1._id is 2 as well!

This is exactly what is happening here. After the first return this, this is modified again with id 2 and name Michael. This causes the returned this to change as well, because they refer to the same object. You never created a new object using new. The same thing happens with the third yield return.

To fix this, simply change Person to a struct (so it's now a value type), or implement the method like JanDotNet did in his answer.


问:
Virtualbox- Cant access to VM when running in Headless mode
I installed an ubuntu server with openssh server on a virtualbox and it works fine. when I start it from GUI I can access it via ssh and Putty, there is no problem. When I start it In headless mode from virtualbox gui there is no problem either.

the problem is, when I run it using VBoxManage startvm "Ubuntu" --type headless it returns a message saying that the Ubuntu is running in headless mode but when I want to connect via ssh to it, its not accessable. my host os is windows 10 and the ubuntu server name is "Ubuntu" and os version is ubuntu-16.04.2-server-x64 and I installed openssh-server and dkms as it described here: https://www.htpcbeginner.com/install-virtualbox-guest-additions-on-ubuntu-debian/

when I work in GUI evrything is fine but I want to run it from windows command line to save some time.

It looks like that the command line vm "Ubuntu" is diffrent from GUI vm "Ubuntu". But I have only one vm on virtualbox. in gui there is one and in cmd vboxmanage list vms returns one vm. so what is the problem?
I also added virtualbox guest addition from Device menu in virtualbox GUI

Edit:

I saw another command : VBoxHeadless --startvm "Ubuntu" its not working either. but unlike the last command it does not show message that Ubuntu is Running. actually it will stuck in execution and the cursor turns to a blinking dash for ever. so I should close the cmd to get ride of it.

I checked something. If I use NAT on network adapter and port forwarding, it works even from cmd. but when using bridge to avoid using port forwarding its not working. in the bridge mode there is connection and ping is working but cant ssh to the Ubuntu.

答: I found the solution. the solution is I should keep the NAT interface as primary as is by default and make a secondary interface in virtualbox gui settings. the secondary interface should be Host-only. then by using this question and its answer I added an interface to guest Ubuntu to a static address. now I can ssh to the static Ip address even if I run the vm from command line, and there is no need to port forwarding.</p>


问:
error while starting another activity
i am starting new activity from current activity but some how before starting activity i am getting Null Pointer exception. and startActivity() from source activity calls sucessfully. I am getting Null Pointer exception. the following is code.

```<code>Intent intent = new Intent(PdfFileSelectActivity.this, PdfViewerActivity.class)
        .putExtra(EXTRA_PDFFILENAME, pdffilename)
        .putExtra(EXTRA_USENIO, useNIO);
</code>```

i checked intenet pdffilename variable and they are not null. and the following is declaration in manifest file.

Hope to hear soon.

答:
you must specify the name of both the activity in androidmanifest.xml file
eg:

```<code>`<activity android:name=".PdfFileSelectActivity"/>
</code>```

this activity is already defined in .xml file but you have also to define this activity

```<code><activity android:name=".PdfViewerActivity"/>
</code>```

after

```<code><application/> tag`
</code>```

Title: error while starting another activity

Body:
i am starting new activity from current activity but some how before starting activity i am getting Null Pointer exception. and startActivity() from source activity calls sucessfully. I am getting Null Pointer exception. the following is code.

Intent intent = new Intent(PdfFileSelectActivity.this, PdfViewerActivity.class)
        .putExtra(EXTRA_PDFFILENAME, pdffilename)
        .putExtra(EXTRA_USENIO, useNIO);

i checked intenet pdffilename variable and they are not null. and the following is declaration in manifest file.

Hope to hear soon.

Body:
you must specify the name of both the activity in androidmanifest.xml file
eg:

`<activity android:name=".PdfFileSelectActivity"/>

this activity is already defined in .xml file but you have also to define this activity

<activity android:name=".PdfViewerActivity"/>

after

<application/> tag`


问:
Wordpress - how to add a code snippet to <head> of each page
I want to add some code to the head of each page that loads using a plugin that I build. What is the proper hook for this and the proper way of doing it? Thanks a lot </p>

答:
For those looking for a sample code, here it is:</p>

```<code>add_action( 'wp_head', 'YOUR_SCRIPT_IN_HEAD_FUNCTION' );
function YOUR_SCRIPT_IN_HEAD_FUNCTION() {
    echo '<script>
        // some code
    </script>';
}
</code>```

Body:
For those looking for a sample code, here it is:

add_action( 'wp_head', 'YOUR_SCRIPT_IN_HEAD_FUNCTION' );
function YOUR_SCRIPT_IN_HEAD_FUNCTION() {
    echo '<script>
        // some code
    </script>';
}


问:
UI-router reloads page on href link click
I'm migrating my angularJS application with ui-router to angular 4 with @uirouter/angular.

I see different behaviour when it comes to links created not via uiSref directive. In @uirouter/angular they reload entire page. Plunker: https://plnkr.co/edit/bF7c29SU1j83opj53Ulc

What is the best workaround to navigate and not reload page?

答:
Turns out, it is problem with angular 2+ itself: Angular 2 Router, href links and unwanted page refresh

I've wrote small script to fix it: https://gist.github.com/Polvista/b19054c705859cef8e38c70de4cf29f8


问:
Google Social SignIn with Spring Boot with Specific Domain
I'm integrating Google+ Signin with Spring Social & Boot.

However it allows me to signIn with @gmail.com domain, but now I want to setup signIn option only for organization. i.e. username@googledomain.com

How can we add specific domain name validation for Spring Social?

答:
When you implement your own signin adapter you have the option to fetch the user profile from the identity provider and with that you are able to validate the e-mail address. The return string here represents the URL to redirect to, so when their e-mail address not matches the domain you could redirect them to an error page without signin them in.</p>

```<code>@Component
public class SocialSignInAdapter implements SignInAdapter {

    private final UserDetailsTransformer userDetailsTransformer;

    @Autowired
    public SocialSignInAdapter(UserDetailsTransformer userDetailsTransformer) {
        this.userDetailsTransformer = userDetailsTransformer;
    }

    @Override
    public String signIn(String localUserId, Connection<?> connection, NativeWebRequest request) {
        if (connection.fetchUserProfile().getEmail().matches("^.*@googledomain.com$")) {
            SecurityContextHolder.getContext().setAuthentication(
                    new UsernamePasswordAuthenticationToken(
                            userDetailsTransformer.convert(connection), null,
                            Arrays.asList(new SimpleGrantedAuthority(String.format("%s_USER", connection.getKey().getProviderId())))));
            return "/";
        } else {
            return "/some-error-page";
        }
    }
}
</code>```

Body:
When you implement your own signin adapter you have the option to fetch the user profile from the identity provider and with that you are able to validate the e-mail address. The return string here represents the URL to redirect to, so when their e-mail address not matches the domain you could redirect them to an error page without signin them in.

@Component
public class SocialSignInAdapter implements SignInAdapter {

    private final UserDetailsTransformer userDetailsTransformer;

    @Autowired
    public SocialSignInAdapter(UserDetailsTransformer userDetailsTransformer) {
        this.userDetailsTransformer = userDetailsTransformer;
    }

    @Override
    public String signIn(String localUserId, Connection<?> connection, NativeWebRequest request) {
        if (connection.fetchUserProfile().getEmail().matches("^.*@googledomain.com$")) {
            SecurityContextHolder.getContext().setAuthentication(
                    new UsernamePasswordAuthenticationToken(
                            userDetailsTransformer.convert(connection), null,
                            Arrays.asList(new SimpleGrantedAuthority(String.format("%s_USER", connection.getKey().getProviderId())))));
            return "/";
        } else {
            return "/some-error-page";
        }
    }
}