Example8.cs

Model: Codex (codedavinci002); Similarity Score: 0.66

Generate

public class EnumDescriptionTypeConverter : EnumConverter

{

   public EnumDescriptionTypeConverter(Type type)

       : base(type)

   {

   }

   public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destinationType)

   {

       if (destinationType == typeof(string))

       {

           if (value != null)

           {

               FieldInfo fi = value.GetType().GetField(value.ToString());

               if (fi != null)

               {

                   var attributes = (DescriptionAttribute[])fi.GetCustomAttributes(typeof(DescriptionAttribute), false);

                   return ((attributes.Length > 0) && (!String.IsNullOrEmpty(attributes[0].Description))) ? attributes[0].Description : value.ToString();

               }

           }

           return string.Empty;

       }

       return base.ConvertTo(context, culture, value, destinationType);

   }

}

Source

public class EnumDescriptionTypeConverter : EnumConverter

{

   public EnumDescriptionTypeConverter(Type type)

       : base(type)

   {

   }

   public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destinationType)

   {

       if (destinationType == typeof(string))

       {

           if (value != null)

           {

               FieldInfo fi = value.GetType().GetField(value.ToString());

               if (fi != null)

               {

                   var attributes = (DescriptionAttribute[])fi.GetCustomAttributes(typeof(DescriptionAttribute), false);

                   return ((attributes.Length > 0) && (!string.IsNullOrEmpty(attributes[0].Description))) ? attributes[0].Description : value.ToString();

               }

           }

           return string.Empty;

       }

       return base.ConvertTo(context, culture, value, destinationType);

   }

}

Example9.cs

Model: Codex (codedavinci002); Similarity Score: 0.68

Generate

partial class Form1

{

   protected override void Dispose(bool disposing)

   {

       if (disposing && (components != null))

       {

           components.Dispose();

       }

       base.Dispose(disposing);

   }


   #region Windows Form Designer generated code

   private void InitializeComponent()

   {

       this.components = new System.ComponentModel.Container();

       System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(Form1));

       this.button1 = new System.Windows.Forms.Button();

       this.button2 = new System.Windows.Forms.Button();

       this.button3 = new System.Windows.Forms.Button();

       this.button

Source

partial class Form1

{

   private System.ComponentModel.IContainer components = null;

   protected override void Dispose(bool disposing)

   {

       if (disposing && (components != null))

       {

           components.Dispose();

       }

       base.Dispose(disposing);

   }


   #region Windows Form Designer generated code

   private void InitializeComponent()

   {

       System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(Form1));

       this.GeneratedPassword = new System.Windows.Forms.TextBox();

       this.Numbers = new System.Windows.Forms.CheckBox();

       this.SmallCapLetters = new System.Windows.Forms.CheckBox();

       this.BigCapLetters = new System.Windows.Forms.CheckBox();

       this.AllSpecialChars = new System.Windows.Forms.CheckBox();...

Example10.cpp

Model: ChatGPT; Similarity Score: 0.66

Generate

/** Example for qpOASES main function using the SQProblem class. */

int main()

{

   // Create an instance of SQProblem class

   SQProblem qp;


   // Define problem dimensions and matrices

   int nV = 2;

   int nC = 1;

   real_t H[2*2] = { 4.0, 1.0, 1.0, 2.0 };

   real_t A[1*2] = { 1.0, 1.0 };

   real_t g[2] = { 1.0, 1.0 };

   real_t lb[2] = { 0.0, 0.0 };

   real_t ub[2] = { 1.0, 1.0 };

   real_t lbA[1] = { 1.0 };

   real_t ubA[1] = { 1.0 };


   // Set up the problem

   int_t nWSR = 10;

   qp.init(H, g, A, lb, ub, lbA, ubA, nWSR);


   // Solve the problem

   real_t xOpt[nV];

   real_t yOpt[nC+1];

   qp.getPrimalSolution(xOpt);

   qp.getDualSolution(yOpt);


   // Print the solution

   cout << "Primal solution:\n";

   for(int i=0; i<nV; i++) {

       cout << "xOpt[" << i << "] = " << xOpt[i] << endl;

   }


   cout << "Dual solution:\n";

   for(int i=0; i<nC+1; i++) {

       cout << "yOpt[" << i << "] = " << yOpt[i] << endl;

   }


   return 0;

}

Source

/** Example for qpOASES main function using the SQProblem class. */

int main( )

{

       USING_NAMESPACE_QPOASES


       /* Setup data of first QP. */

       real_t H[2*2] = { 1.0, 0.0, 0.0, 0.5 };

       real_t A[1*2] = { 1.0, 1.0 };

       real_t g[2] = { 1.5, 1.0 };

       real_t lb[2] = { 0.5, -2.0 };

       real_t ub[2] = { 5.0, 2.0 };

       real_t lbA[1] = { -1.0 };

       real_t ubA[1] = { 2.0 };


       /* Setup data of second QP. */

       real_t H_new[2*2] = { 1.0, 0.5, 0.5, 0.5 };

       real_t A_new[1*2] = { 1.0, 5.0 };

       real_t g_new[2] = { 1.0, 1.5 };

       real_t lb_new[2] = { 0.0, -1.0 };

       real_t ub_new[2] = { 5.0, -0.5 };

       real_t lbA_new[1] = { -2.0 };

       real_t ubA_new[1] = { 1.0 };



       /* Setting up SQProblem object. */

       SQProblem example( 2,1 );


       /* Solve first QP. */

       int nWSR = 10;

       example.init( H,g,A,lb,ub,lbA,ubA, nWSR,0 );


       /* Solve second QP. */

       nWSR = 10;

       example.hotstart( H_new,g_new,A_new,lb_new,ub_new,lbA_new,ubA_new, nWSR,0 );


       /* Get and print solution of second QP. */

       real_t xOpt[2];

       example.getPrimalSolution( xOpt );

       printf( "\nxOpt = [ %e, %e ];  objVal = %e\n\n", xOpt[0],xOpt[1],example.getObjVal() );


       return 0;

}

Example11.c

Model: GPT-4; Similarity Score: 0.69

Generate

static GList *g_list_sort_merge(GList *l1, GList *l2, GFunc compare_func, gpointer user_data) {

   GList list, *l, *lprev;

   gint cmp;


   l = &list;

   lprev = NULL;


   while (l1 && l2) {

       cmp = compare_func(l1->data, l2->data, user_data);


       if (cmp <= 0) {

           l->next = l1;

           l1 = l1->next;

       } else {

           l->next = l2;

           l2 = l2->next;

       }


       l->next->prev = lprev;

       lprev = l->next;

       l = lprev;

   }


   l->next = l1 ? l1 : l2;

   l->next->prev = lprev;


   return list.next;

}

Source

static GList *

g_list_sort_merge (GList     *l1,

                  GList     *l2,

                  GFunc     compare_func,

                  gpointer  user_data)

{

 GList list, *l, *lprev;

 gint cmp;


 l = &list;

 lprev = NULL;


 while (l1 && l2)

   {

     cmp = ((GCompareDataFunc) compare_func) (l1->data, l2->data, user_data);


     if (cmp <= 0)

       {

         l->next = l1;

         l1 = l1->next;

       }

     else

       {

         l->next = l2;

         l2 = l2->next;

       }

     l = l->next;

     l->prev = lprev;

     lprev = l;

   }

 l->next = l1 ? l1 : l2;

 l->next->prev = l;


 return list.next;

}