added 7 characters in body
Source Link
tcokyasar
  • 1.2k
  • 2
  • 10
### BEGIN DECLARING THE MODEL ###
m= Model('CTA''Some_model')
### END DECLARING THE MODEL ###

### BEGIN ADDING VARIABLES INTO THE MODEL m ###
freq = m.continuous_var_dict(Pattern, lb=1, ub=15, name ='freq')
invfreq = m.continuous_var_dict(Pattern, lb=1, ub=15, name ='invfreq')
### END ADDING VARIABLES INTO THE MODEL m ###

### BEGIN INTRODUCING THE OBJECTIVE FUNCTION INTO m ###
m.maximize(m.sum(0.5*crt_ridership[pat,s]*(30-30*invfreq[pat])
                        for (pat,s) in PatternStop))
### END INTRODUCING THE OBJECTIVE FUNCTION ###

### BEGIN ADDING CONSTRAINTS INTO m ###
m.add_constraint(m.sum(unit_cost[pat]*triptime[pat]*freq[pat]/60 for pat in Pattern)
                    - m.sum(FixedFare*crt_ridership[pat,s] for (pat,s) in PatternStop) <= S)

m.add_constraints(m.sum(triptimesurrogate[pat]*freq[pat]/30 
    for pat in Pattern if(pattern_time_index[pat]==p and pattern_bus_cap[pat]==82))
    <= FleetAvailSmall[p] for p in Period)
m.add_constraints(m.sum(triptimesurrogate[pat]*freq[pat]/30 
    for pat in Pattern if(pattern_time_index[pat]==p and pattern_bus_cap[pat]==107))
    <= FleetAvailLarge[p] for p in Period)
m.add_constraints(m.sum(triptimesurrogate[pat]*freq[pat]/30 
    for pat in Pattern if(pattern_time_index[pat]==p and pattern_bus_cap[pat]==246))
    <= FleetAvail2Car[p] for p in Period)
m.add_constraints(m.sum(triptimesurrogate[pat]*freq[pat]/30 
    for pat in Pattern if(pattern_time_index[pat]==p and pattern_bus_cap[pat]==492))
    <= FleetAvail4Car[p] for p in Period)
m.add_constraints(m.sum(triptimesurrogate[pat]*freq[pat]/30 
    for pat in Pattern if(pattern_time_index[pat]==p and pattern_bus_cap[pat]==738))
    <= FleetAvail6Car[p] for p in Period)
m.add_constraints(m.sum(triptimesurrogate[pat]*freq[pat]/30 
    for pat in Pattern if(pattern_time_index[pat]==p and pattern_bus_cap[pat]==984))
    <= FleetAvail8Car[p] for p in Period)
                  
m.add_constraints(crt_flow[pat,s] <= pattern_bus_cap[pat]*freq[pat] for (pat,s) in PatternStop)
    
m.add(freq[pat]*invfreq[pat] >= abs(1) for pat in Pattern)
### END ADDING CONSTRAINTS INTO m ###

solution = m.solve(log_output=True)
print(solution)
### BEGIN DECLARING THE MODEL ###
m= Model('CTA')
### END DECLARING THE MODEL ###

### BEGIN ADDING VARIABLES INTO THE MODEL m ###
freq = m.continuous_var_dict(Pattern, lb=1, ub=15, name ='freq')
invfreq = m.continuous_var_dict(Pattern, lb=1, ub=15, name ='invfreq')
### END ADDING VARIABLES INTO THE MODEL m ###

### BEGIN INTRODUCING THE OBJECTIVE FUNCTION INTO m ###
m.maximize(m.sum(0.5*crt_ridership[pat,s]*(30-30*invfreq[pat])
                        for (pat,s) in PatternStop))
### END INTRODUCING THE OBJECTIVE FUNCTION ###

### BEGIN ADDING CONSTRAINTS INTO m ###
m.add_constraint(m.sum(unit_cost[pat]*triptime[pat]*freq[pat]/60 for pat in Pattern)
                    - m.sum(FixedFare*crt_ridership[pat,s] for (pat,s) in PatternStop) <= S)

m.add_constraints(m.sum(triptimesurrogate[pat]*freq[pat]/30 
    for pat in Pattern if(pattern_time_index[pat]==p and pattern_bus_cap[pat]==82))
    <= FleetAvailSmall[p] for p in Period)
m.add_constraints(m.sum(triptimesurrogate[pat]*freq[pat]/30 
    for pat in Pattern if(pattern_time_index[pat]==p and pattern_bus_cap[pat]==107))
    <= FleetAvailLarge[p] for p in Period)
m.add_constraints(m.sum(triptimesurrogate[pat]*freq[pat]/30 
    for pat in Pattern if(pattern_time_index[pat]==p and pattern_bus_cap[pat]==246))
    <= FleetAvail2Car[p] for p in Period)
m.add_constraints(m.sum(triptimesurrogate[pat]*freq[pat]/30 
    for pat in Pattern if(pattern_time_index[pat]==p and pattern_bus_cap[pat]==492))
    <= FleetAvail4Car[p] for p in Period)
m.add_constraints(m.sum(triptimesurrogate[pat]*freq[pat]/30 
    for pat in Pattern if(pattern_time_index[pat]==p and pattern_bus_cap[pat]==738))
    <= FleetAvail6Car[p] for p in Period)
m.add_constraints(m.sum(triptimesurrogate[pat]*freq[pat]/30 
    for pat in Pattern if(pattern_time_index[pat]==p and pattern_bus_cap[pat]==984))
    <= FleetAvail8Car[p] for p in Period)
                  
m.add_constraints(crt_flow[pat,s] <= pattern_bus_cap[pat]*freq[pat] for (pat,s) in PatternStop)
    
m.add(freq[pat]*invfreq[pat] >= abs(1) for pat in Pattern)
### END ADDING CONSTRAINTS INTO m ###

solution = m.solve(log_output=True)
print(solution)
### BEGIN DECLARING THE MODEL ###
m= Model('Some_model')
### END DECLARING THE MODEL ###

### BEGIN ADDING VARIABLES INTO THE MODEL m ###
freq = m.continuous_var_dict(Pattern, lb=1, ub=15, name ='freq')
invfreq = m.continuous_var_dict(Pattern, lb=1, ub=15, name ='invfreq')
### END ADDING VARIABLES INTO THE MODEL m ###

### BEGIN INTRODUCING THE OBJECTIVE FUNCTION INTO m ###
m.maximize(m.sum(0.5*crt_ridership[pat,s]*(30-30*invfreq[pat])
                        for (pat,s) in PatternStop))
### END INTRODUCING THE OBJECTIVE FUNCTION ###

### BEGIN ADDING CONSTRAINTS INTO m ###
m.add_constraint(m.sum(unit_cost[pat]*triptime[pat]*freq[pat]/60 for pat in Pattern)
                    - m.sum(FixedFare*crt_ridership[pat,s] for (pat,s) in PatternStop) <= S)

m.add_constraints(m.sum(triptimesurrogate[pat]*freq[pat]/30 
    for pat in Pattern if(pattern_time_index[pat]==p and pattern_bus_cap[pat]==82))
    <= FleetAvailSmall[p] for p in Period)
m.add_constraints(m.sum(triptimesurrogate[pat]*freq[pat]/30 
    for pat in Pattern if(pattern_time_index[pat]==p and pattern_bus_cap[pat]==107))
    <= FleetAvailLarge[p] for p in Period)
m.add_constraints(m.sum(triptimesurrogate[pat]*freq[pat]/30 
    for pat in Pattern if(pattern_time_index[pat]==p and pattern_bus_cap[pat]==246))
    <= FleetAvail2Car[p] for p in Period)
m.add_constraints(m.sum(triptimesurrogate[pat]*freq[pat]/30 
    for pat in Pattern if(pattern_time_index[pat]==p and pattern_bus_cap[pat]==492))
    <= FleetAvail4Car[p] for p in Period)
m.add_constraints(m.sum(triptimesurrogate[pat]*freq[pat]/30 
    for pat in Pattern if(pattern_time_index[pat]==p and pattern_bus_cap[pat]==738))
    <= FleetAvail6Car[p] for p in Period)
m.add_constraints(m.sum(triptimesurrogate[pat]*freq[pat]/30 
    for pat in Pattern if(pattern_time_index[pat]==p and pattern_bus_cap[pat]==984))
    <= FleetAvail8Car[p] for p in Period)
                  
m.add_constraints(crt_flow[pat,s] <= pattern_bus_cap[pat]*freq[pat] for (pat,s) in PatternStop)
    
m.add(freq[pat]*invfreq[pat] >= abs(1) for pat in Pattern)
### END ADDING CONSTRAINTS INTO m ###

solution = m.solve(log_output=True)
print(solution)
Source Link
tcokyasar
  • 1.2k
  • 2
  • 10

Rotated Second-Order Cone Constraints in docplex

I have programmed the model in here using Gurobi 9.0 in Python 3.7. To ensure playing within the boundaries of the licensing, I am trying to program it using CPLEX where we have broader flexibility under a commercial license. I have two short questions.

First, is DoCplex the same as Cplex in Python, if not can you please refer to an example implementation?

Second, how can I introduce the rotated second-order cone constraints in this coding? I checked Docplex functions and couldn't see something relevant.

### BEGIN DECLARING THE MODEL ###
m= Model('CTA')
### END DECLARING THE MODEL ###

### BEGIN ADDING VARIABLES INTO THE MODEL m ###
freq = m.continuous_var_dict(Pattern, lb=1, ub=15, name ='freq')
invfreq = m.continuous_var_dict(Pattern, lb=1, ub=15, name ='invfreq')
### END ADDING VARIABLES INTO THE MODEL m ###

### BEGIN INTRODUCING THE OBJECTIVE FUNCTION INTO m ###
m.maximize(m.sum(0.5*crt_ridership[pat,s]*(30-30*invfreq[pat])
                        for (pat,s) in PatternStop))
### END INTRODUCING THE OBJECTIVE FUNCTION ###

### BEGIN ADDING CONSTRAINTS INTO m ###
m.add_constraint(m.sum(unit_cost[pat]*triptime[pat]*freq[pat]/60 for pat in Pattern)
                    - m.sum(FixedFare*crt_ridership[pat,s] for (pat,s) in PatternStop) <= S)

m.add_constraints(m.sum(triptimesurrogate[pat]*freq[pat]/30 
    for pat in Pattern if(pattern_time_index[pat]==p and pattern_bus_cap[pat]==82))
    <= FleetAvailSmall[p] for p in Period)
m.add_constraints(m.sum(triptimesurrogate[pat]*freq[pat]/30 
    for pat in Pattern if(pattern_time_index[pat]==p and pattern_bus_cap[pat]==107))
    <= FleetAvailLarge[p] for p in Period)
m.add_constraints(m.sum(triptimesurrogate[pat]*freq[pat]/30 
    for pat in Pattern if(pattern_time_index[pat]==p and pattern_bus_cap[pat]==246))
    <= FleetAvail2Car[p] for p in Period)
m.add_constraints(m.sum(triptimesurrogate[pat]*freq[pat]/30 
    for pat in Pattern if(pattern_time_index[pat]==p and pattern_bus_cap[pat]==492))
    <= FleetAvail4Car[p] for p in Period)
m.add_constraints(m.sum(triptimesurrogate[pat]*freq[pat]/30 
    for pat in Pattern if(pattern_time_index[pat]==p and pattern_bus_cap[pat]==738))
    <= FleetAvail6Car[p] for p in Period)
m.add_constraints(m.sum(triptimesurrogate[pat]*freq[pat]/30 
    for pat in Pattern if(pattern_time_index[pat]==p and pattern_bus_cap[pat]==984))
    <= FleetAvail8Car[p] for p in Period)
                  
m.add_constraints(crt_flow[pat,s] <= pattern_bus_cap[pat]*freq[pat] for (pat,s) in PatternStop)
    
m.add(freq[pat]*invfreq[pat] >= abs(1) for pat in Pattern)
### END ADDING CONSTRAINTS INTO m ###

solution = m.solve(log_output=True)
print(solution)