Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

One constraint present in all heuristics discussed in class is that one person c

ID: 3604324 • Letter: O

Question

One constraint present in all heuristics discussed in class is that one person cannot be assigned more than one task. Consider a scenario where this constraint is relaxed (i.e. one person can be assigned multiple (or zero) tasks). Develop a heuristic in pseudocode and write a Python program that tries to minimize the total cost, where each task must be assigned exactly once and each person can be assigned multiple (or zero) tasks. Call your code lap_h5.py. Run this program with a 200x200 csv file represent 200 people and 200 tasks. Display your results in a table on your Word document similar to the one below. Problem Instance H5 4 5

Explanation / Answer

#include <stdio.h>

main() {

   unsigned int a = 60;   /* 60 = 0011 1100 */

   unsigned int b = 13;   /* 13 = 0000 1101 */

   int c = 0;

   c = a & b; /* 12 = 0000 1100 */

   printf("c = a & b; - Value of c is %d ", c );

   c = a << 2; /* 240 = 1111 0000 */

   printf("c = a << 2; - Value of c is %d ", c );

   c = a >> 2; /* 15 = 0000 1111 */

   printf("a = a >> 2; - Value of c is %d ", c );

}

So what we want to do is look at each bit on the integer and if the bit at position i

is a one print a ‘1’ if the bit is a zero print ‘0’.

Consider the following Java method:

static void showbits(int bits){

for(int i=31; i>=0; i--)

   System.out.print( (( (bits >> i) & 1) > 0) ? 1 : 0) ;

System.out.print(" ");

   }

or a less concise version

static void showbits(int bits){

for(int i=31; i>=0; i--){

   int value = bits >> i;

   if ((value & 1) == 1)

System.out.print("1");

   else

           System.out.print("0");

}

System.out.print(" ");

   }

The ‘bits’ is the formal parameter that is passed in. We use a for loop and walk down

the array from Most Significant Bit (MSB) to the least significant bit (63 to 0). For

each bit we check if it is one or zero. We walk down the array by doing a bitwise

shift (>>) and check each bit with a bitwise AND (&). Easy, no.

So we read in a long int. I recommend reading in the long int value as follows:

   long int i;

   printf(" Please enter a long integer value: ");

   scanf(“%li",&i);  

we could then test if the highest bit place has a one or a zero

by making a mask that would have a 1 and then 63 zeros

e.g. 10000000000000000000000000000000000000000000000000000000000000

      long int mask = (1L << 63);

Note long will be 64 bits so mask and the ‘1’ should also be qualified as a LONG (L)

Then we can do a bitwise AND with our number and test if the result greater than zero.

(Or if you want you could shift the other way and test if result is zero.) If this bit was on

(value 1) print ‘1’ else print ‘0’.

      if( (i & mask) > 0)

       printf("1");

      else

       printf(“0”);

For the floating-point (64-bit double), we want to do the same kind of thing.

Read in a double:

   double f;

   printf(" Please enter a floating point number: ");

   scanf(“&lf", &f);

but here we need to trick the compiler into treating the float as though it was an integer

The author's idea is to use an union with int and a char[4]

   union longdouble {

          unsigned long i;

          double d

   }ld;

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote