Example #1
0
File: id_dp.c Project: B-Rich/simh
t_bool dp_dter (UNIT *uptr, uint32 first)
{
uint32 hd, sc, sa;
uint32 dtype = GET_DTYPE (uptr->flags);                 /* get drive type */

if (((uptr->flags & UNIT_ATT) == 0) ||                  /* not attached? */
    ((uptr->flags & UNIT_WPRT) && (dp_cmd == CMC_WR))) {
    dp_done (STC_DTE);                                  /* error, done */
    return TRUE;
    }
hd = GET_SRF (dp_hdsc);                                 /* get head */
sc = GET_SEC (dp_hdsc);                                 /* get sector */
if (dp_cyl != (uint32) uptr->CYL) {                     /* wrong cylinder? */
    if (dp_cyl == 0)
        uptr->CYL = 0;
    else {
        dp_done (STC_ACF);                              /* error, done */
        return TRUE;
        } 
    }
if (sc >= DP_NUMSC) {                                   /* bad sector? */
    dp_done (STC_OVR);                                  /* error, done */
    return TRUE;
    }
if (!first && (sc == 0) && (hd == 0)) {                 /* cyl overflow? */
    dp_done (STC_CYO);                                  /* error, done */
    return TRUE;
    }
sa = GET_SA (dp_plat, uptr->CYL, hd, sc, dtype);        /* curr disk addr */
fseek (uptr->fileref, sa * DP_NUMBY, SEEK_SET);
if ((sc + 1) < DP_NUMSC)                                /* end of track? */
    dp_hdsc = dp_hdsc + 1;
else dp_hdsc = (dp_hdsc ^ HS_HMASK) & HS_HMASK;         /* sec 0, nxt srf */
return FALSE;
}
Example #2
0
/* print all 0-1 solutions to the lp into the outstream */
void print_bin_solutions_lp(LinearProgram* lp) {
    num_t* configuration = allocate(lp->cols, sizeof(*configuration));
    unsigned long count = 1UL << lp->cols;
    unsigned int feasible_solutions = 0;

    print_matrix(lp);
    printf("\n");

    clock_t start = clock();

    unsigned int i;
    for (i = 0; i < count; i++) {
        if (is_feasible(configuration, lp)) {
            __print_config(configuration, lp->cols);
            feasible_solutions++;
        }
        next_configuration(configuration, lp->cols);
    }

    double elapsed = GET_SEC(start, clock());
    printf("Checked %lu vectors in %.3f s = %.3f kvecs/s\n",
            count, elapsed, (double) count / elapsed / 1000.0);

    deallocate(configuration);
    printf("found %u feasible solutions\n", feasible_solutions);
}
Example #3
0
long bip_enumerate(const bip bip, bool with_output)
{
        assert(is_initialized(bip));
        clock_t start = clock();
        long long     solus = 0;
        long long     count = 0;
    if (with_output)printf("The solution vectors are: \n");
        for(unsigned long long bitvec = 0; bitvec < (1uL << bip.columns); bitvec++)
           {
              unsigned long long mask = 1;  // long long because long is 32 bit on 32 bit computers
                   int    x[bip.columns];
            
                assert(sizeof(bitvec) * 8 > bip.columns); //lint !e506
                  for(int j = 0; j < bip.columns; j++, mask <<= 1)
                          x[j] = (bitvec & mask) ? 1.0 : 0.0;
               if (bip.ordin==eq) {
                   if (is_Solution_eq(bip, x)){
                       if (with_output)
                           print_solution(x, bip.columns);
                       
                       solus++;
                   }
               }else{
                   if (is_Solution(bip, x)) //lint !e772
                   {
                       if (with_output)
                           print_solution(x, bip.columns);
                       
                       solus++;
                   }
               }
               
                  count++;
            }
       assert((unsigned)count == (1u << bip.columns));
    
        double elapsed = GET_SEC(start, clock());
    
        printf(" %lld vectors were tested in %.3f s = %.3f kvecs/s\n",
                    count, elapsed, count / elapsed / 1000.0);
    
        return solus;
     }