GLPK MathProg sets and groups - solver

I hope this is obvious to someone. I have only had a vanilla use of GLPK/MathProg.
I am having trouble figuring out the syntax in GNU MathProg (within GLPK) to do the following, for example:
set PartsOfWeek;
set WeekDays;
data;
set PartsOfWeek := WorkWeek WeekEnd;
set WorkWeek := Mon Tue Wed Thu Fri;
set WeekEnd := Sat Sun;
set WeekDays := setof{d in (WorkWeek union WeekEnd)}(d);
The problem is that this is rejected by MathProg.
In general, I just want to be able to:
- declare a Partition (here PartsOfWeek) and a set (here Weekdays)
- build the partition from data
- populate the set with the elements of the of the sets from the partition.
A better example might be with seasons and months.

with #ALi's literature reference help:
set seasons;
set months;
set monthsOfseason {seasons} within months;
data;
set seasons := winter spring summer fall;
set months := jan feb mar apr may jun jul aug sep oct nov dec;
set monthsOfseason[winter] := dec jan feb;
set monthsOfseason[spring] := mar apr may;
set monthsOfseason[summer] := jun jul aug;
set monthsOfseason[fall] := sep oct nov;

Related

How to get month name 12 months back with asp classic?

I want to display the short name for each month, 12 months back from the previous month, but with the below I get an error on mon1 and mon2 and I guess since that is last year?
mon1=MonthName(Month(Now())-11,1)
mon2=MonthName(Month(Now())-10,1)
mon3=MonthName(Month(Now())-9,1)
mon4=MonthName(Month(Now())-8,1)
mon5=MonthName(Month(Now())-7,1)
mon6=MonthName(Month(Now())-6,1)
mon7=MonthName(Month(Now())-5,1)
mon8=MonthName(Month(Now())-4,1)
mon9=MonthName(Month(Now())-3,1)
mon10=MonthName(Month(Now())-2,1)
mon11=MonthName(Month(Now())-1,1)
mon12=MonthName(Month(Now()),1)
So how can I display now,dec,jan,feb,mar,apr,may,jun,jul,aug,sep,oct
Thanks.
The problem here is the Month() function returns an integer between 1 and 12 to represent each month. Instead you want to minus the number of months from the Now() value before wrapping it with Month().
Below is an example that does this using a For loop and a single dimension Array.
Dim dt: dt = Now()
Dim i, mon(12)
Const numOfMonths = 12
For i = 1 To numOfMonths
mon(i) = MonthName(Month(DateAdd("m", i - numOfMonths, dt)), True)
Next
Call Response.Write(Join(mon, vbCrLf))
Output:
Sep
Aug
Jul
Jun
May
Apr
Mar
Feb
Jan
Dec
Nov
Oct

FORTRAN : maxloc

my data looks like
JAN FEB MAR APR MAY JUN JUL AUG SEP OCT NOV DEC
22.60 24.60 30.60 34.60 36.20 35.70 32.10 30.20 31.40 31.60 28.00 24.80
25.40 27.60 32.40 34.60 36.50 38.10 31.70 31.40 30.30 30.20 27.00 23.90
and there are like hundreds of rows! I want to find a maximum value in each row and write it in different column next to data along with month
so my out put will be
36.20 MAY
38.10 JUN
.
.
I want to use maxloc function, but i have no idea how to use it!
Try
index = maxloc(myTable(3,:))
print *, myTable((/1,3/), index)
It should select the highest value from the third row and display the first and third value at this index.

Sort a hash with key as month date with many values for the same month

I create a hash with months as keys and timelaps as values
biens_delai[bien_date.mon] = b.delai
I get this result without month parsing
{Wed, 18 Jan 2017=>3.0, Sat, 25 Feb 2017=>2.0, Fri, 17 Mar 2017=>3.0, Sat, 25 Mar 2017=>5.0, Tue, 18 Apr 2017=>2.0, Thu, 29 Jun 2017=>2.0}
In March i have 2 values but when i parse by month i get the most high value and i want a addition of 2 values for March not the most high
{1=>3.0, 2=>2.0, 3=>5.0, 4=>2.0, 6=>2.0}
That's not the high value which you are getting, the values are getting overwritten, try the following
biens_delai[bien_date.mon] = biens_delai[bien_date.mon].to_f + b.delai

Grouping collection by year and month in Laravel

I have a collection, that I would like to achieve group by the year and month.
2014
jan
2nd
5th
...
feb
11th
12th
...
mar
...
2013
jan
feb
mar
...
2012
jan
feb
mar
...
this is my current collection but only by year. I couldn't get what I really wanted with this.
$collection =$model->orderBy('date', 'desc')->get()->groupBy(function($item) {
return $item->date->format('Y');
});
Do a Group By on DB::raw('MONTH(your date variable)')
For example, try this:
$model->orderBy('date')->groupBy(DB::raw('MONTH(date)'))->selectRaw('DATE_FORMAT(date, "%M %Y") as Month)->get();

How to detect time in Go?

I need to parse the date_id field from emails headers. However these seem to have slightly different layouts so I've started to build a switch case/block . I'm wondering if that's really the way to fix this issue.
case strings.Contains(h.Headers[bk].Date, "(CEST)"):
layout = "Mon, 02 Jan 2006 15:04:05 -0700 (MST)"
case strings.Contains(h.Headers[bk].Date, "(EDT)"):
layout = "Mon, 02 Jan 2006 15:04:05 -0700 (MST)"
default:
layout = "Mon, 02 Jan 2006 15:04:05 -0700"
}
You could use mail.Header and simply call .Date() on it.
Another option is to read the code starting from line 70 and write your own function.

Resources